From: Claudio Cambra Date: Wed, 23 Oct 2024 05:42:21 +0000 (+0800) Subject: Do not attempt to reach out to FileProviderExt every single time we want to check... X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~58^2^2~67^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2214c1d3d524a31fddeffe8b862f5f9522a9f29e;p=nextcloud-desktop.git Do not attempt to reach out to FileProviderExt every single time we want to check if it is reachable Only check every 60 seconds, this way we do not freeze the client for 3 seconds every time that we want to check the reachability while the extension is unreachable Signed-off-by: Claudio Cambra --- diff --git a/src/gui/macOS/fileproviderxpc.h b/src/gui/macOS/fileproviderxpc.h index 4ca88c03b..737657cba 100644 --- a/src/gui/macOS/fileproviderxpc.h +++ b/src/gui/macOS/fileproviderxpc.h @@ -14,6 +14,7 @@ #include #include +#include #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> fastEnumerationStateForExtension(const QString &extensionAccountId) const; @@ -53,6 +54,7 @@ private slots: private: QHash _clientCommServices; + QDateTime _lastUnreachableTime; }; } // namespace OCC::Mac diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index b7128cf69..2cc522ac4 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -22,6 +22,7 @@ namespace { constexpr int64_t semaphoreWaitDelta = 3000000000; // 3 seconds + constexpr auto reachableRetryTimeout = 60; // 60 seconds } namespace OCC::Mac { @@ -143,12 +144,19 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc } } -bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) const +bool FileProviderXPC::fileProviderExtReachable(const QString &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 *)_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 +164,11 @@ bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, semaphoreWaitDelta)); + + if (!response) { + qCWarning(lcFileProviderXPC) << "Could not reach file provider extension."; + _lastUnreachableTime = QDateTime::currentDateTime(); + } return response; }