Do not attempt to reach out to FileProviderExt every single time we want to check...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 23 Oct 2024 05:42:21 +0000 (13:42 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 5 Nov 2024 05:59:13 +0000 (14:59 +0900)
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 <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderxpc.h
src/gui/macOS/fileproviderxpc_mac.mm

index 4ca88c03bd5bec71c35bf7d62faf28bca296ee44..737657cbaf3d6cbb9d196ffa259d6e8fd20c27d1 100644 (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;
+    QDateTime _lastUnreachableTime;
 };
 
 } // namespace OCC::Mac
index b7128cf6941c8db76cea301419a41b42b810c703..2cc522ac455dc3e9a17e35213300810c92568ec9 100644 (file)
@@ -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<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 +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;
 }