Skip to content

Commit

Permalink
Merge pull request #7459 from nextcloud/backport/7397/stable-3.14
Browse files Browse the repository at this point in the history
[stable-3.14] Fix stuttering and freezing of client while computing sync state changes (macOS VFS)
  • Loading branch information
claucambra authored Nov 5, 2024
2 parents e358eb5 + 38dba44 commit 182e06b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/gui/macOS/fileproviderxpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <QObject>
#include <QHash>
#include <QDateTime>

#include "accountstate.h"

Expand All @@ -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;
Expand All @@ -53,6 +54,7 @@ private slots:

private:
QHash<QString, void*> _clientCommServices;
QHash<QString, QDateTime> _unreachableAccountExtensions;
};

} // namespace OCC::Mac
20 changes: 18 additions & 2 deletions src/gui/macOS/fileproviderxpc_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -143,19 +144,34 @@
}
}

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) {
response = true;
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;
}

Expand Down

0 comments on commit 182e06b

Please sign in to comment.