Reduce number of UI updates when running indexer at startup.

This commit is contained in:
casey 2016-07-05 00:11:23 -07:00
parent 7aa27a231c
commit e3281d5506
2 changed files with 7 additions and 7 deletions

View File

@ -293,6 +293,7 @@ void Indexer::ReadMetadataFromFile(
if (saveToDb) {
track.SetValue("path_id", pathId.c_str());
track.Save(this->dbConnection, this->libraryPath);
this->filesSaved++;
}
}
@ -300,23 +301,21 @@ static inline void joinAndNotify(
std::vector<Thread>& threads,
std::shared_ptr<musik::core::db::ScopedTransaction> transaction,
sigslot::signal0<>& event,
size_t& total)
std::atomic<size_t>& saved)
{
total += threads.size();
for (size_t i = 0; i < threads.size(); i++) {
threads.at(i)->join();
}
threads.clear();
if (total > 200) {
if (saved.load() > 200) {
if (transaction) {
transaction->CommitAndRestart();
}
event();
total = 0;
saved.store(0);
}
}

View File

@ -49,6 +49,7 @@
#include <deque>
#include <vector>
#include <atomic>
#define INDEXER_PREFS_COMPONENT "indexer"
#define INDEXER_PREFS_SYNC_ON_STARTUP "SyncOnStartup"
@ -105,7 +106,7 @@ namespace musik { namespace core {
boost::mutex progressMutex;
size_t filesIndexed;
size_t filesSaved;
std::atomic<size_t> filesSaved;
struct AddRemoveContext {
bool add;
@ -124,7 +125,7 @@ namespace musik { namespace core {
DecoderList audioDecoders;
std::shared_ptr<musik::core::Preferences> prefs;
std::shared_ptr<musik::core::db::ScopedTransaction> trackTransaction;
int maxReadThreads;
size_t maxReadThreads;
};
typedef std::shared_ptr<Indexer> IndexerPtr;