[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/strigi/src
From:       Jos van den Oever <jos () vandenoever ! info>
Date:       2007-05-07 22:26:59
Message-ID: 1178576819.328866.31172.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 662343 by vandenoever:

improve update function for updating multiple directories at once, possibly in multiple threads

 M  +30 -13    streamanalyzer/diranalyzer.cpp  
 M  +3 -0      streamanalyzer/diranalyzer.h  
 M  +1 -4      strigicmd/strigicmd.cpp  


--- trunk/kdesupport/strigi/src/streamanalyzer/diranalyzer.cpp #662342:662343
@@ -31,7 +31,8 @@
         STRIGI_MUTEX_DESTROY(&updateMutex);
     }
     int analyzeDir(const string& dir, int nthreads, bool (*continueAnalysis)());
-    int updateDir(const string& dir, int nthreads, bool (*continueAnalysis)());
+    int updateDirs(const vector<string>& dir, int nthreads,
+        bool (*continueAnalysis)());
     void analyze(StreamAnalyzer*);
     void update(StreamAnalyzer*);
 };
@@ -99,9 +100,10 @@
                 bool newfile = i == dbfiles.end();
                 bool updatedfile = !newfile && i->second != mtime;
 
-                // if the file is new or was modified: erase the indexed version
-                if (updatedfile) {
-                    dbfiles.erase(path);
+                // if the file is not new or updated, remove it from the list
+                // of files to be removed from the index
+                if (!newfile && !updatedfile) {
+                    dbfiles.erase(i);
                 }
                 STRIGI_MUTEX_UNLOCK(&updateMutex);
 
@@ -172,10 +174,12 @@
 }
 int
 DirAnalyzer::updateDir(const string& dir, int nthreads, bool (*cont)()) {
-    return p->updateDir(dir, nthreads, 0);
+    vector<string> dirs;
+    dirs.push_back(dir);
+    return p->updateDirs(dirs, nthreads, cont);
 }
 int
-DirAnalyzer::Private::updateDir(const string& dir, int nthreads,
+DirAnalyzer::Private::updateDirs(const vector<string>& dirs, int nthreads,
         bool (*cont)()) {
     IndexReader* reader = manager.indexReader();
     if (reader == 0) return -1;
@@ -194,26 +198,39 @@
     }
     vector<STRIGI_THREAD_TYPE> threads;
     threads.resize(nthreads-1);
-    for (int i=1; i<nthreads; i++) {
-        DA* da = new DA();
-        da->diranalyzer = this;
-        da->streamanalyzer = analyzers[i];
-        STRIGI_THREAD_CREATE(&threads[i-1], updateInThread, da);
+
+    for (vector<string>::const_iterator d =dirs.begin(); d != dirs.end(); ++d) {
+        lister.startListing(*d);
+        for (int i=1; i<nthreads; i++) {
+            DA* da = new DA();
+            da->diranalyzer = this;
+            da->streamanalyzer = analyzers[i];
+            STRIGI_THREAD_CREATE(&threads[i-1], updateInThread, da);
+        }
+        update(analyzers[0]); 
+        for (int i=1; i<nthreads; i++) {
+            STRIGI_THREAD_JOIN(threads[i-1]);
+        }
     }
-    update(analyzers[0]); 
     for (int i=1; i<nthreads; i++) {
-        STRIGI_THREAD_JOIN(threads[i-1]);
         delete analyzers[i];
     }
 
     // remove the files that were not encountered from the index
     vector<string> todelete(dbfiles.size());
+    fprintf(stderr, "to delete: %i\n", dbfiles.size());
     map<string,time_t>::iterator it = dbfiles.begin();
     while (it != dbfiles.end()) {
         todelete.push_back(it->first);
+        ++it;
     }
     manager.indexWriter()->deleteEntries(todelete);
     dbfiles.clear();
 
     return 0;
 }
+int
+DirAnalyzer::updateDirs(const std::vector<std::string>& dirs, int nthreads,
+        bool (*continueAnalysis)()) {
+    return p->updateDirs(dirs, nthreads, continueAnalysis);
+}
--- trunk/kdesupport/strigi/src/streamanalyzer/diranalyzer.h #662342:662343
@@ -3,6 +3,7 @@
 
 #include "strigiconfig.h"
 #include <string>
+#include <vector>
 
 namespace Strigi {
 class IndexManager;
@@ -19,6 +20,8 @@
         bool (*continueAnalysis)() = 0);
     int updateDir(const std::string& dir, int nthreads = 2,
         bool (*continueAnalysis)() = 0);
+    int updateDirs(const std::vector<std::string>& dirs, int nthreads = 2,
+        bool (*continueAnalysis)() = 0);
 };
 }
 #endif
--- trunk/kdesupport/strigi/src/strigicmd/strigicmd.cpp #662342:662343
@@ -261,10 +261,7 @@
 
     AnalyzerConfiguration config;
     DirAnalyzer* analyzer = new DirAnalyzer(*manager, config);
-    vector<string>::const_iterator j;
-    for (j = dirs.begin(); j != dirs.end(); ++j) {
-        analyzer->updateDir(j->c_str(), nthreads);
-    }
+    analyzer->updateDirs(dirs, nthreads);
     delete analyzer;
     delete manager;
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic