]> cloud.milkyroute.net Git - dolphin.git/commitdiff
KDirectoryContentsCounter: scan first path not in cache
authorMéven Car <meven29@gmail.com>
Mon, 25 May 2020 15:31:51 +0000 (15:31 +0000)
committerMéven Car <meven29@gmail.com>
Mon, 25 May 2020 15:31:51 +0000 (15:31 +0000)
Use a secondary QLinkedList to store the priority path.

src/kitemviews/private/kdirectorycontentscounter.cpp
src/kitemviews/private/kdirectorycontentscounter.h

index a0ed8c27cadc0320dd3ec4b5d32f46b405a67a8a..05a6ff447465cf69853acf4f364728f2b6c954b8 100644 (file)
@@ -103,7 +103,9 @@ void KDirectoryContentsCounter::slotResult(const QString& path, int count, long
         m_watchedDirs.insert(resolvedPath);
     }
 
-    if (!m_queue.isEmpty()) {
+    if (!m_priorityQueue.isEmpty()) {
+        startWorker(m_priorityQueue.takeLast());
+    } else if (!m_queue.isEmpty()) {
         startWorker(m_queue.takeFirst());
     }
 
@@ -167,7 +169,8 @@ void KDirectoryContentsCounter::slotItemsRemoved()
 
 void KDirectoryContentsCounter::startWorker(const QString& path)
 {
-    if (s_cache->contains(path)) {
+    const bool alreadyInCache = s_cache->contains(path);
+    if (alreadyInCache) {
         // fast path when in cache
         // will be updated later if result has changed
         const auto pair = s_cache->value(path);
@@ -175,8 +178,13 @@ void KDirectoryContentsCounter::startWorker(const QString& path)
     }
 
     if (m_workerIsBusy) {
-        if (!m_queue.contains(path)) {
-            m_queue.append(path);
+        if (!m_queue.contains(path) && !m_priorityQueue.contains(path)) {
+            if (alreadyInCache) {
+                m_queue.append(path);
+            } else {
+                // append to priority queue
+                m_priorityQueue.append(path);
+            }
         }
     } else {
         KDirectoryContentsCounterWorker::Options options;
index 287227bffb76aba149226523dceff685b2ccf026..01bf3077917138749e5b4782c433093a2110f528 100644 (file)
@@ -72,6 +72,7 @@ private:
 private:
     KFileItemModel* m_model;
 
+    QLinkedList<QString> m_priorityQueue;
     QLinkedList<QString> m_queue;
 
     static QThread* m_workerThread;