diff --git a/src/file/fileindexerconfig.h b/src/file/fileindexerconfig.h --- a/src/file/fileindexerconfig.h +++ b/src/file/fileindexerconfig.h @@ -190,6 +190,8 @@ /// Caching cleaned up list (no duplicates, no useless entries, etc.) QList > m_folderCache; + /// Whether the folder cache needs to be rebuilt the next time it is used + bool m_folderCacheDirty; /// cache of regexp objects for all exclude filters /// to prevent regexp parsing over and over diff --git a/src/file/fileindexerconfig.cpp b/src/file/fileindexerconfig.cpp --- a/src/file/fileindexerconfig.cpp +++ b/src/file/fileindexerconfig.cpp @@ -58,8 +58,9 @@ FileIndexerConfig::FileIndexerConfig(QObject* parent) : QObject(parent) , m_config(QStringLiteral("baloofilerc")) + , m_folderCacheDirty(true) , m_indexHidden(false) - , m_devices(new StorageDevices(this)) + , m_devices(nullptr) , m_maxUncomittedFiles(40) { forceConfigUpdate(); @@ -73,6 +74,8 @@ QStringList FileIndexerConfig::includeFolders() const { + const_cast(this)->buildFolderCache(); + QStringList fl; for (int i = 0; i < m_folderCache.count(); ++i) { if (m_folderCache[i].second) @@ -84,6 +87,8 @@ QStringList FileIndexerConfig::excludeFolders() const { + const_cast(this)->buildFolderCache(); + QStringList fl; for (int i = 0; i < m_folderCache.count(); ++i) { if (!m_folderCache[i].second) @@ -147,6 +152,8 @@ } else if (shouldFolderBeIndexed(path)) { return true; } + + const_cast(this)->buildFolderCache(); // Look for included descendants for (const QPair& fld: m_folderCache) { @@ -225,6 +232,8 @@ bool FileIndexerConfig::folderInFolderList(const QString& path, QString& folder) const { + const_cast(this)->buildFolderCache(); + const QString p = stripTrailingSlash(path); // we traverse the list backwards to catch all exclude folders @@ -300,6 +309,14 @@ void FileIndexerConfig::buildFolderCache() { + if (!m_folderCacheDirty) { + return; + } + + if (!m_devices) { + m_devices = new StorageDevices(this); + } + KConfigGroup group = m_config.group("General"); QStringList includeFoldersPlain = group.readPathEntry("folders", QStringList() << QDir::homePath()); QStringList excludeFoldersPlain = group.readPathEntry("exclude folders", QStringList()); @@ -320,6 +337,8 @@ insertSortFolders(excludeFoldersPlain, false, m_folderCache); cleanupList(m_folderCache); + + m_folderCacheDirty = false; } @@ -338,7 +357,7 @@ { m_config.reparseConfiguration(); - buildFolderCache(); + m_folderCacheDirty = true; buildExcludeFilterRegExpCache(); buildMimeTypeCache();