[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/runtime/nepomuk/services/strigi
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2010-12-10 9:54:39
Message-ID: 20101210095439.A4CD5AC8A8 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1205173 by trueg:
* Give higher preference to manually added index folders. This way changed files are updated quicker
and newly added files are instantly in the index - even during initial indexing.
M +64 -25 indexscheduler.cpp
M +11 -3 indexscheduler.h
--- trunk/KDE/kdebase/runtime/nepomuk/services/strigi/indexscheduler.cpp #1205172:1205173
@@ -110,6 +110,53 @@
}
+void Nepomuk::IndexScheduler::UpdateDirQueue::enqueueDir( const QString& dir, UpdateDirFlags flags )
+{
+ if( contains( qMakePair( dir, flags ) ) )
+ return;
+
+ if( !(flags & AutoUpdateFolder) ) {
+ int i = 0;
+ while( i < count() && !(at(i).second & AutoUpdateFolder) )
+ ++i;
+ insert( i, qMakePair( dir, flags ) );
+ }
+ else {
+ enqueue( qMakePair( dir, flags ) );
+ }
+}
+
+
+void Nepomuk::IndexScheduler::UpdateDirQueue::prependDir( const QString& dir, UpdateDirFlags flags )
+{
+ if( contains( qMakePair( dir, flags ) ) )
+ return;
+
+ if( flags & AutoUpdateFolder ) {
+ int i = 0;
+ while( i < count() && !(at(i).second & AutoUpdateFolder) )
+ ++i;
+ insert( i, qMakePair( dir, flags ) );
+ }
+ else {
+ prepend( qMakePair( dir, flags ) );
+ }
+}
+
+
+void Nepomuk::IndexScheduler::UpdateDirQueue::clearByFlags( UpdateDirFlags mask )
+{
+ QQueue<QPair<QString, UpdateDirFlags> >::iterator it = begin();
+ while ( it != end() ) {
+ if ( it->second & mask )
+ it = erase( it );
+ else
+ ++it;
+ }
+}
+
+
+
Nepomuk::IndexScheduler::IndexScheduler( QObject* parent )
: QThread( parent ),
m_suspended( false ),
@@ -283,8 +330,7 @@
// get the next folder
m_dirsToUpdateMutex.lock();
- QPair<QString, UpdateDirFlags> dir = *m_dirsToUpdate.begin();
- m_dirsToUpdate.erase( m_dirsToUpdate.begin() );
+ QPair<QString, UpdateDirFlags> dir = m_dirsToUpdate.dequeue();
m_dirsToUpdateMutex.unlock();
// update until stopped
@@ -334,7 +380,6 @@
QHash<QString, QDateTime>::iterator filesInStoreEnd = filesInStore.end();
QList<QFileInfo> filesToIndex;
- QStringList subFolders;
QStringList filesToDelete;
// iterate over all files in the dir
@@ -360,6 +405,8 @@
bool fileChanged = !newFile && fileInfo.lastModified() != filesInStoreIt.value();
if ( fileChanged )
kDebug() << "CHANGED:" << path << fileInfo.lastModified() << filesInStoreIt.value();
+ else if( forceUpdate )
+ kDebug() << "UPDATE FORCED:" << path;
if ( indexFile && ( newFile || fileChanged || forceUpdate ) )
filesToIndex << fileInfo;
@@ -373,9 +420,16 @@
if ( !newFile )
filesInStore.erase( filesInStoreIt );
- if ( indexFile && recursive && fileInfo.isDir() && !fileInfo.isSymLink() )
- subFolders << path;
+ // prepend sub folders to the dir queue
+ if ( indexFile &&
+ recursive &&
+ fileInfo.isDir() &&
+ !fileInfo.isSymLink() &&
+ StrigiServiceConfig::self()->shouldFolderBeIndexed( path ) ) {
+ QMutexLocker lock( &m_dirsToUpdateMutex );
+ m_dirsToUpdate.prependDir( path, flags );
}
+ }
// all the files left in filesInStore are not in the current
// directory and should be deleted
@@ -396,16 +450,6 @@
m_currentUrl = KUrl();
}
- // recurse into subdirs (we do this in a separate loop to always keep a proper state:
- // compare m_currentFolder)
- if ( recursive ) {
- foreach( const QString& folder, subFolders ) {
- if ( StrigiServiceConfig::self()->shouldFolderBeIndexed( folder ) &&
- !analyzeDir( folder, flags ) )
- return false;
- }
- }
-
return true;
}
@@ -429,7 +473,7 @@
void Nepomuk::IndexScheduler::updateDir( const QString& path, bool forceUpdate )
{
QMutexLocker lock( &m_dirsToUpdateMutex );
- m_dirsToUpdate << qMakePair( path, UpdateDirFlags( forceUpdate ? ForceUpdate : NoUpdateFlags ) );
+ m_dirsToUpdate.prependDir( path, UpdateDirFlags( forceUpdate ? ForceUpdate : NoUpdateFlags ) );
m_dirsToUpdateWc.wakeAll();
}
@@ -446,22 +490,17 @@
QMutexLocker lock( &m_dirsToUpdateMutex );
// remove previously added folders to not index stuff we are not supposed to
- QSet<QPair<QString, UpdateDirFlags> >::iterator it = m_dirsToUpdate.begin();
- while ( it != m_dirsToUpdate.end() ) {
- if ( it->second & AutoUpdateFolder )
- it = m_dirsToUpdate.erase( it );
- else
- ++it;
- }
+ m_dirsToUpdate.clearByFlags( AutoUpdateFolder );
UpdateDirFlags flags = UpdateRecursive|AutoUpdateFolder;
if ( forceUpdate )
flags |= ForceUpdate;
// update everything again in case the folders changed
- foreach( const QString& f, StrigiServiceConfig::self()->includeFolders() )
- m_dirsToUpdate << qMakePair( f, flags );
+ foreach( const QString& f, StrigiServiceConfig::self()->includeFolders() ) {
+ m_dirsToUpdate.enqueueDir( f, flags );
}
+}
void Nepomuk::IndexScheduler::slotConfigChanged()
--- trunk/KDE/kdebase/runtime/nepomuk/services/strigi/indexscheduler.h #1205172:1205173
@@ -22,7 +22,7 @@
#include <QtCore/QThread>
#include <QtCore/QMutex>
#include <QtCore/QWaitCondition>
-#include <QtCore/QSet>
+#include <QtCore/QQueue>
#include <QtCore/QDateTime>
#include <vector>
@@ -219,8 +219,16 @@
Indexer* m_indexer;
- // set of folders to update (+flags defined in the source file) - changed by updateDir
- QSet<QPair<QString, UpdateDirFlags> > m_dirsToUpdate;
+ // A specialized queue that gives priority to dirs that do not use the AutoUpdateFolder flag.
+ class UpdateDirQueue : public QQueue<QPair<QString, UpdateDirFlags> >
+ {
+ public:
+ void enqueueDir( const QString& dir, UpdateDirFlags flags );
+ void prependDir( const QString& dir, UpdateDirFlags flags );
+ void clearByFlags( UpdateDirFlags mask );
+ };
+ // queue of folders to update (+flags defined in the source file) - changed by updateDir
+ UpdateDirQueue m_dirsToUpdate;
QMutex m_dirsToUpdateMutex;
QWaitCondition m_dirsToUpdateWc;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic