logic: improved performance of initializing the fulltext search index

* implemented using multithreaing for building the fulltext search index
* also: decreased ideal thread count by 1 to keep the machine responsive while indexing and building the index
This commit is contained in:
mlangkabel
2018-04-10 12:40:51 +02:00
parent 7dde56ea6a
commit 835aedd669
6 changed files with 74 additions and 45 deletions
+21 -5
View File
@@ -25,6 +25,7 @@
#include "utility/TimeStamp.h"
#include "utility/tracing.h"
#include "utility/utility.h"
#include "utility/utilityApp.h"
PersistentStorage::PersistentStorage(const FilePath& dbPath, const FilePath& bookmarkPath)
: m_sqliteIndexStorage(dbPath)
@@ -2741,13 +2742,28 @@ void PersistentStorage::buildFullTextSearchIndex() const
m_fullTextSearchCodec = codec.getName();
m_fullTextSearchIndex.clear();
for (StorageFile& file : m_sqliteIndexStorage.getAll<StorageFile>())
{
m_fullTextSearchIndex.addFile(
file.id,
codec.decode(m_sqliteIndexStorage.getFileContentById(file.id)->getText())
std::vector<std::shared_ptr<std::thread>> threads;
for (std::vector<StorageFile> part : utility::splitToEqualySizedParts(m_sqliteIndexStorage.getAll<StorageFile>(), utility::getIdealThreadCount()))
{
std::shared_ptr<std::thread> thread = std::make_shared<std::thread>(
[&](const std::vector<StorageFile>& files)
{
for (const StorageFile& file : files)
{
m_fullTextSearchIndex.addFile(
file.id,
codec.decode(m_sqliteIndexStorage.getFileContentById(file.id)->getText())
);
}
},
part
);
threads.push_back(thread);
}
for (std::shared_ptr<std::thread> thread : threads)
{
thread->join();
}
}