New discovery algorithm: Call FolderDiscovered
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 6 Aug 2018 10:53:51 +0000 (12:53 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:02 +0000 (10:58 +0100)
src/libsync/discoveryphase.cpp
src/libsync/syncengine.cpp
src/libsync/syncengine.h

index e4cd5b9a5dd2a9018beab8df04bea584c8ad8c62..d765634c629bd17be5c902e983bbf68f3a7f21b0 100644 (file)
@@ -162,30 +162,6 @@ void DiscoveryPhase::startJob(ProcessDirectoryJob *job)
     job->start();
 }
 
-/* FIXME  (used to be called every time we were doing a propfind)
-void DiscoveryJob::update_job_update_callback(bool local,
-    const char *dirUrl,
-    void *userdata)
-{
-    auto *updateJob = static_cast<DiscoveryJob *>(userdata);
-    if (updateJob) {
-        // Don't wanna overload the UI
-        if (!updateJob->_lastUpdateProgressCallbackCall.isValid()
-         || updateJob->_lastUpdateProgressCallbackCall.elapsed() >= 200) {
-            updateJob->_lastUpdateProgressCallbackCall.start();
-        } else {
-            return;
-        }
-
-        QByteArray pPath(dirUrl);
-        int indx = pPath.lastIndexOf('/');
-        if (indx > -1) {
-            const QString path = QUrl::fromPercentEncoding(pPath.mid(indx + 1));
-            emit updateJob->folderDiscovered(local, path);
-        }
-    }
-}*/
-
 DiscoverySingleDirectoryJob::DiscoverySingleDirectoryJob(const AccountPtr &account, const QString &path, QObject *parent)
     : QObject(parent)
     , _subPath(path)
index 2b4a3633643a4530f7fa906cd6bc49278d7b999b..ffbc65350b7605ee75e6a985742668294c0a591b 100644 (file)
@@ -380,6 +380,10 @@ void OCC::SyncEngine::slotItemDiscovered(const OCC::SyncFileItemPtr &item)
     _needsUpdate = true;
     _syncItems.append(item);
     slotNewItem(item);
+
+    if (item->isDirectory()) {
+        slotFolderDiscovered(item->_etag.isEmpty(), item->_file);
+    }
 }
 
 void SyncEngine::startSync()
@@ -627,9 +631,15 @@ void SyncEngine::slotStartDiscovery()
 
 void SyncEngine::slotFolderDiscovered(bool local, const QString &folder)
 {
-    // Currently remote and local discovery never run in parallel
-    // Note: Currently this slot is only called occasionally! See the throttling
-    //       in DiscoveryJob::update_job_update_callback.
+    // Don't wanna overload the UI
+    if (!_lastUpdateProgressCallbackCall.isValid()) {
+        _lastUpdateProgressCallbackCall.start(); // first call
+    } else if (_lastUpdateProgressCallbackCall.elapsed() < 200) {
+        return;
+    } else {
+        _lastUpdateProgressCallbackCall.start();
+    }
+
     if (local) {
         _progressInfo->_currentDiscoveredLocalFolder = folder;
         _progressInfo->_currentDiscoveredRemoteFolder.clear();
index 90f00a8aaa9f4417baa4080880d60ce8e599ef50..1343fc493948de758c0c0bfaa5cd1b4a2d69c7ae 100644 (file)
@@ -289,6 +289,8 @@ private:
     /** Stores the time since a job touched a file. */
     QMultiMap<QElapsedTimer, QString> _touchedFiles;
 
+    QElapsedTimer _lastUpdateProgressCallbackCall;
+
     /** For clearing the _touchedFiles variable after sync finished */
     QTimer _clearTouchedFilesTimer;