Skip to content

Commit 40e5978

Browse files
committed
Make sync scheduling more predictable
1 parent 3fc36a2 commit 40e5978

File tree

5 files changed

+11
-74
lines changed

5 files changed

+11
-74
lines changed

src/gui/folder.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "account.h"
2020
#include "accountstate.h"
2121
#include "application.h"
22-
#include "common/checksums.h"
2322
#include "common/depreaction.h"
2423
#include "common/filesystembase.h"
2524
#include "common/syncjournalfilerecord.h"
@@ -55,9 +54,6 @@
5554
#include <QTimer>
5655
#include <QUrl>
5756

58-
#include <QApplication>
59-
#include <QMessageBox>
60-
6157
using namespace Qt::Literals::StringLiterals;
6258
using namespace std::chrono_literals;
6359

@@ -85,7 +81,9 @@ Folder::Folder(const FolderDefinition &definition, const AccountStatePtr &accoun
8581
_timeSinceLastSyncStart.start();
8682
_timeSinceLastSyncDone.start();
8783

88-
setSyncState(definition.paused ? SyncResult::Paused : SyncResult::Queued);
84+
// set the sync state without emiting a signal
85+
_syncResult.setStatus(definition.paused ? SyncResult::Paused : SyncResult::Queued);
86+
8987
// check if the local path exists
9088
if (checkLocalPath()) {
9189
// those errors should not persist over sessions
@@ -100,7 +98,8 @@ Folder::Folder(const FolderDefinition &definition, const AccountStatePtr &accoun
10098

10199
connect(_accountState.data(), &AccountState::isConnectedChanged, this, &Folder::canSyncChanged);
102100

103-
connect(_engine.data(), &SyncEngine::finished, this, &Folder::slotSyncFinished);
101+
// use a direct connection, the folder status has to be up to date
102+
connect(_engine.data(), &SyncEngine::finished, this, &Folder::slotSyncFinished, Qt::DirectConnection);
104103

105104
connect(_engine.data(), &SyncEngine::transmissionProgress, this,
106105
[this](const ProgressInfo &pi) { Q_EMIT ProgressDispatcher::instance()->progressInfo(this, pi); });
@@ -398,8 +397,8 @@ void Folder::setSyncState(SyncResult::Status state)
398397
{
399398
const auto oldIsRunning = isSyncRunning();
400399
if (state != _syncResult.status()) {
400+
qCDebug(lcFolder) << u"State of" << path() << u"changed to" << state << u"old state" << _syncResult.status();
401401
_syncResult.setStatus(state);
402-
qCDebug(lcFolder) << u"State of" << path() << u"changed to" << state;
403402
Q_EMIT syncStateChange();
404403
if (oldIsRunning != isSyncRunning()) {
405404
Q_EMIT isSyncRunningChanged();
@@ -882,9 +881,7 @@ void Folder::startSync()
882881
}
883882

884883
_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);
885-
QMetaObject::invokeMethod(_engine.data(), &SyncEngine::startSync, Qt::QueuedConnection);
886-
887-
Q_EMIT syncStarted();
884+
_engine->startSync();
888885
}
889886

890887
void Folder::setDirtyNetworkLimits()
@@ -936,7 +933,6 @@ void Folder::slotSyncFinished(bool success)
936933
qCInfo(lcFolder) << u"SyncEngine finished without problem.";
937934
}
938935
_fileLog->finish();
939-
showSyncResultPopup();
940936

941937
auto anotherSyncNeeded = false;
942938

@@ -975,10 +971,10 @@ void Folder::slotSyncFinished(bool success)
975971

976972
if (syncStatus != SyncResult::Undefined) {
977973
setSyncState(syncStatus);
974+
showSyncResultPopup();
978975
}
979976

980-
// syncStateChange from setSyncState needs to be emitted first
981-
QTimer::singleShot(0, this, [this] { Q_EMIT syncFinished(_syncResult); });
977+
Q_EMIT syncFinished(_syncResult);
982978

983979
_lastSyncDuration = std::chrono::milliseconds(_timeSinceLastSyncStart.elapsed());
984980
_timeSinceLastSyncDone.start();

src/gui/folder.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ class OPENCLOUD_GUI_EXPORT Folder : public QObject
222222

223223
Q_SIGNALS:
224224
void syncStateChange();
225-
void syncStarted();
226225
void syncFinished(const SyncResult &result);
227226
void syncPausedChanged(Folder *, bool paused);
228227
void canSyncChanged();
@@ -352,8 +351,6 @@ private Q_SLOTS:
352351

353352
QScopedPointer<SyncRunFileLog> _fileLog;
354353

355-
QTimer _scheduleSelfTimer;
356-
357354
/**
358355
* Setting up vfs is a async operation
359356
*/

src/gui/folderman.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -381,34 +381,6 @@ bool FolderMan::isAnySyncRunning() const
381381
return false;
382382
}
383383

384-
void FolderMan::slotFolderSyncStarted()
385-
{
386-
auto f = qobject_cast<Folder *>(sender());
387-
OC_ASSERT(f);
388-
if (!f)
389-
return;
390-
391-
qCInfo(lcFolderMan) << u">========== Sync started for folder [" << f->shortGuiLocalPath() << u"] of account ["
392-
<< f->accountState()->account()->displayNameWithHost() << u"]";
393-
}
394-
395-
/*
396-
* a folder indicates that its syncing is finished.
397-
* Start the next sync after the system had some milliseconds to breath.
398-
* This delay is particularly useful to avoid late file change notifications
399-
* (that we caused ourselves by syncing) from triggering another spurious sync.
400-
*/
401-
void FolderMan::slotFolderSyncFinished(const SyncResult &)
402-
{
403-
auto f = qobject_cast<Folder *>(sender());
404-
OC_ASSERT(f);
405-
if (!f)
406-
return;
407-
408-
qCInfo(lcFolderMan) << u"<========== Sync finished for folder [" << f->shortGuiLocalPath() << u"] of account ["
409-
<< f->accountState()->account()->displayNameWithHost() << u"]";
410-
}
411-
412384
Folder *FolderMan::addFolder(const AccountStatePtr &accountState, const FolderDefinition &folderDefinition)
413385
{
414386
// Choose a db filename
@@ -452,8 +424,6 @@ Folder *FolderMan::addFolderInternal(
452424
// See matching disconnects in unloadFolder().
453425
if (!folder->hasSetupError()) {
454426
connect(folder, &Folder::syncStateChange, _socketApi.get(), [folder, this] { _socketApi->slotUpdateFolderView(folder); });
455-
connect(folder, &Folder::syncStarted, this, &FolderMan::slotFolderSyncStarted);
456-
connect(folder, &Folder::syncFinished, this, &FolderMan::slotFolderSyncFinished);
457427
connect(folder, &Folder::syncStateChange, this, [folder, this] { Q_EMIT folderSyncStateChange(folder); });
458428
connect(folder, &Folder::syncPausedChanged, this, &FolderMan::slotFolderSyncPaused);
459429
connect(folder, &Folder::canSyncChanged, this, &FolderMan::slotFolderCanSyncChanged);

src/gui/folderman.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,6 @@ class TrayOverallStatusResult
5555
SyncResult _overallStatus;
5656
};
5757

58-
/**
59-
* @brief The FolderMan class
60-
* @ingroup gui
61-
*
62-
* The FolderMan knows about all loaded folders and is responsible for
63-
* scheduling them when necessary.
64-
*
65-
* A folder is scheduled if:
66-
* - The configured force-sync-interval has expired
67-
* (_timeScheduler and slotScheduleFolderByTime())
68-
*
69-
* - A folder watcher receives a notification about a file change
70-
* (_folderWatchers and Folder::slotWatchedPathsChanged())
71-
*
72-
* - The folder etag on the server has changed
73-
* (_etagPollTimer)
74-
*
75-
* - The locks of a monitored file are released
76-
* (_lockWatcher and slotWatchedFileUnlocked())
77-
*
78-
* - There was a sync error or a follow-up sync is requested
79-
* (_timeScheduler and slotScheduleFolderByTime()
80-
* and Folder::slotSyncFinished())
81-
*/
8258
class OPENCLOUD_GUI_EXPORT FolderMan : public QObject
8359
{
8460
Q_OBJECT
@@ -282,8 +258,6 @@ public Q_SLOTS:
282258
private Q_SLOTS:
283259
void slotFolderSyncPaused(Folder *, bool paused);
284260
void slotFolderCanSyncChanged();
285-
void slotFolderSyncStarted();
286-
void slotFolderSyncFinished(const SyncResult &);
287261

288262
void slotRemoveFoldersForAccount(const AccountStatePtr &accountState);
289263

src/gui/scheduling/syncscheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void SyncScheduler::startNext()
235235
_currentSync.clear();
236236
startNext();
237237
},
238-
Qt::SingleShotConnection);
238+
static_cast<Qt::ConnectionType>(Qt::DirectConnection | Qt::SingleShotConnection));
239239
qCInfo(lcSyncScheduler) << u"Starting sync for" << _currentSync->path() << u"QueueSize:" << _queue->size();
240240
_currentSync->startSync();
241241
_syncTimer.reset();
@@ -268,7 +268,7 @@ Folder *SyncScheduler::currentSync()
268268
void SyncScheduler::terminateCurrentSync(const QString &reason)
269269
{
270270
if (_currentSync && _currentSync->isReady()) {
271-
qCInfo(lcSyncScheduler) << u"folder " << _currentSync->path() << _currentSync->syncState() << u" Terminating!";
271+
qCInfo(lcSyncScheduler) << u"folder" << _currentSync->path() << _currentSync->syncState() << u"Terminating!";
272272
if (OC_ENSURE(_currentSync->syncEngine().isSyncRunning())) {
273273
_currentSync->syncEngine().abort(reason);
274274
}

0 commit comments

Comments
 (0)