diff options
author | Klaas Freitag <kfreitag@owncloud.com> | 2021-08-16 11:37:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 11:37:56 +0300 |
commit | a668053c7549e2685b4b5334c5b8e71d07007168 (patch) | |
tree | 315d685a3cd3905af30e54ab98e94d55ebdacf20 /src/gui/folder.cpp | |
parent | 49b415b3eff72eedaf30e0e8f945559adc00911f (diff) |
Poll interval from capabilities (#8777)
* Add remotePollInterval capability.
* Use public const int rather than define for default value.
* Honour pollinterval from account capabilities for poll frequency.
With this, admins can change the remote poll interval of desktop
clients with the capability settings.
* Use more efficient invocation of the etag job slot.
* Consider capability value to be in milliseconds.
* Make format check happy.
* Add a ElapsedTimer to measure time since last Etag check.
Also, do the check if one of the folders is due to sync every
second. That way we get a more accurate sync frequency. The
check is very lightweight.
* Extend remotePollInterval config method to accept default value.
With that it is possible to read the value for the remotepollinterval
from the capabilities.
* Add changelog entry for #8777.
* Changes from clang-format
* Fix changelog entry, punctuation at end.
* do not go for assumptions how long the request takes. No magic number.
* Change some method interfaces to seconds rather than microseconds.
Feedback from review.
* Again considering more review feedback
* Remove additional 5s check already performed in ConfigFile::remotePollInterval
Co-authored-by: Hannah von Reth <hannah.vonreth@owncloud.com>
Diffstat (limited to 'src/gui/folder.cpp')
-rw-r--r-- | src/gui/folder.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 1ccfa868b..31124cd31 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -68,6 +68,7 @@ Folder::Folder(const FolderDefinition &definition, { _timeSinceLastSyncStart.start(); _timeSinceLastSyncDone.start(); + _timeSinceLastEtagCheckDone.start(); SyncResult::Status status = SyncResult::NotYetStarted; if (definition.paused) { @@ -285,6 +286,27 @@ bool Folder::canSync() const return !syncPaused() && accountState()->isConnected(); } +bool Folder::dueToSync() const +{ + // conditions taken from previous folderman implementation + if (isSyncRunning() || etagJob() || isBusy() || !canSync()) { + return false; + } + + ConfigFile cfg; + // the default poll time of 30 seconds as it had been in the client forever. + // Now with https://github.com/owncloud/client/pull/8777 also the server capabilities are considered. + const auto pta = accountState()->account()->capabilities().remotePollInterval(); + const auto polltime = cfg.remotePollInterval(pta); + + const auto timeSinceLastSync = std::chrono::milliseconds(_timeSinceLastEtagCheckDone.elapsed()); + qCInfo(lcFolder) << "dueToSync:" << alias() << timeSinceLastSync.count() << " < " << polltime.count(); + if (timeSinceLastSync >= polltime) { + return true; + } + return false; +} + void Folder::setSyncPaused(bool paused) { if (paused == _definition.paused) { @@ -343,6 +365,7 @@ void Folder::slotRunEtagJob() _requestEtagJob->setTimeout(60 * 1000); // check if the etag is different when retrieved QObject::connect(_requestEtagJob.data(), &RequestEtagJob::etagRetreived, this, &Folder::etagRetreived); + QObject::connect(_requestEtagJob.data(), &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QByteArray>) { _timeSinceLastEtagCheckDone.start(); }); FolderMan::instance()->slotScheduleETagJob(alias(), _requestEtagJob); // The _requestEtagJob is auto deleting itself on finish. Our guard pointer _requestEtagJob will then be null. } |