Propagator: Make sure we schedule only one job #7439
authorMarkus Goetz <markus@woboq.com>
Fri, 30 Aug 2019 09:37:07 +0000 (11:37 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:58 +0000 (10:58 +0100)
To not starve the event loop.
(There is still ~= 3 jobs running at the same time)

src/libsync/owncloudpropagator.cpp
src/libsync/owncloudpropagator.h

index 83b067270685f2443befdd200aa680db9307005e..856b2e25fa162aa5dee8622dbea81f6e70752112 100644 (file)
@@ -487,6 +487,7 @@ void OwncloudPropagator::start(const SyncFileItemVector &items)
 
     connect(_rootJob.data(), &PropagatorJob::finished, this, &OwncloudPropagator::emitFinished);
 
+    _jobScheduled = false;
     scheduleNextJob();
 }
 
@@ -587,6 +588,8 @@ QString OwncloudPropagator::getFilePath(const QString &tmp_file_name) const
 
 void OwncloudPropagator::scheduleNextJob()
 {
+    if (_jobScheduled) return; // don't schedule more than 1
+    _jobScheduled = true;
     QTimer::singleShot(0, this, &OwncloudPropagator::scheduleNextJobImpl);
 }
 
@@ -597,6 +600,8 @@ void OwncloudPropagator::scheduleNextJobImpl()
     // Down-scaling on slow networks? https://github.com/owncloud/client/issues/3382
     // Making sure we do up/down at same time? https://github.com/owncloud/client/issues/1633
 
+    _jobScheduled = false;
+
     if (_activeJobList.count() < maximumActiveTransferJob()) {
         if (_rootJob->scheduleSelfOrChild()) {
             scheduleNextJob();
index 0febc6ab7e686f99680ffa5cf22b519420e21741..c5431f051f6538ac4e68734284223591c260a8ea 100644 (file)
@@ -567,6 +567,7 @@ private:
     AccountPtr _account;
     QScopedPointer<PropagateDirectory> _rootJob;
     SyncOptions _syncOptions;
+    bool _jobScheduled = false;
 };