Merge pull request #7397 from nextcloud/bugfix/mac-vfs-syncstatechange-freeze

Fix stuttering and freezing of client while computing sync state changes (macOS VFS)
This commit is contained in:
Claudio Cambra 2024-11-05 14:59:30 +09:00 committed by GitHub
commit 01da699e7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View file

@ -14,6 +14,7 @@
#include <QObject>
#include <QHash>
#include <QDateTime>
#include "accountstate.h"
@ -34,7 +35,7 @@ class FileProviderXPC : public QObject
public:
explicit FileProviderXPC(QObject *parent = nullptr);
[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId) const;
[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId);
// Returns enabled and set state of fast enumeration for the given extension
[[nodiscard]] std::optional<std::pair<bool, bool>> fastEnumerationStateForExtension(const QString &extensionAccountId) const;
@ -53,6 +54,7 @@ private slots:
private:
QHash<QString, void*> _clientCommServices;
QHash<QString, QDateTime> _unreachableAccountExtensions;
};
} // namespace OCC::Mac

View file

@ -21,7 +21,8 @@
#include "gui/macOS/fileproviderxpc_mac_utils.h"
namespace {
constexpr int64_t semaphoreWaitDelta = 3000000000; // 3 seconds
constexpr int64_t semaphoreWaitDelta = 1000000000; // 1 seconds
constexpr auto reachableRetryTimeout = 300; // seconds
}
namespace OCC::Mac {
@ -143,12 +144,20 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc
}
}
bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) const
bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId)
{
const auto lastUnreachableTime = _unreachableAccountExtensions.value(extensionAccountId);
if (lastUnreachableTime.isValid() && lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) {
qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. "
<< "Not checking again";
return false;
}
const auto service = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
if (service == nil) {
return false;
}
__block auto response = false;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[service getExtensionAccountIdWithCompletionHandler:^(NSString *const, NSError *const) {
@ -156,6 +165,13 @@ bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, semaphoreWaitDelta));
if (response) {
_unreachableAccountExtensions.remove(extensionAccountId);
} else {
qCWarning(lcFileProviderXPC) << "Could not reach file provider extension.";
_unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime());
}
return response;
}