]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kdirectorycontentscounter.cpp
KDirectoryContentsCounter: scan first path not in cache
[dolphin.git] / src / kitemviews / private / kdirectorycontentscounter.cpp
index a19bce8b3b061cd6b0ba3685b2a4603257056510..05a6ff447465cf69853acf4f364728f2b6c954b8 100644 (file)
@@ -103,8 +103,10 @@ void KDirectoryContentsCounter::slotResult(const QString& path, int count, long
         m_watchedDirs.insert(resolvedPath);
     }
 
-    if (!m_queue.isEmpty()) {
-        startWorker(m_queue.dequeue());
+    if (!m_priorityQueue.isEmpty()) {
+        startWorker(m_priorityQueue.takeLast());
+    } else if (!m_queue.isEmpty()) {
+        startWorker(m_queue.takeFirst());
     }
 
     if (s_cache->contains(resolvedPath)) {
@@ -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,7 +178,14 @@ void KDirectoryContentsCounter::startWorker(const QString& path)
     }
 
     if (m_workerIsBusy) {
-        m_queue.enqueue(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;