Changeset View
Changeset View
Standalone View
Standalone View
src/file/filecontentindexer.cpp
Show All 21 Lines | |||||
22 | #include "extractorprocess.h" | 22 | #include "extractorprocess.h" | ||
23 | 23 | | |||
24 | #include <QEventLoop> | 24 | #include <QEventLoop> | ||
25 | #include <QElapsedTimer> | 25 | #include <QElapsedTimer> | ||
26 | #include <QDBusConnection> | 26 | #include <QDBusConnection> | ||
27 | 27 | | |||
28 | using namespace Baloo; | 28 | using namespace Baloo; | ||
29 | 29 | | |||
30 | FileContentIndexer::FileContentIndexer(FileIndexerConfig* config, FileContentIndexerProvider* provider, QObject* parent) | 30 | FileContentIndexer::FileContentIndexer(FileIndexerConfig* config, | ||
31 | FileContentIndexerProvider* provider, | ||||
32 | uint& finishedCount, QObject* parent) | ||||
31 | : QObject(parent) | 33 | : QObject(parent) | ||
32 | , m_config(config) | 34 | , m_config(config) | ||
33 | , m_batchSize(config->maxUncomittedFiles()) | 35 | , m_batchSize(config->maxUncomittedFiles()) | ||
34 | , m_provider(provider) | 36 | , m_provider(provider) | ||
37 | , m_finishedCount(finishedCount) | ||||
35 | , m_stop(0) | 38 | , m_stop(0) | ||
36 | { | 39 | { | ||
37 | Q_ASSERT(provider); | 40 | Q_ASSERT(provider); | ||
38 | 41 | | |||
39 | QDBusConnection bus = QDBusConnection::sessionBus(); | 42 | QDBusConnection bus = QDBusConnection::sessionBus(); | ||
40 | m_monitorWatcher.setConnection(bus); | 43 | m_monitorWatcher.setConnection(bus); | ||
41 | m_monitorWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); | 44 | m_monitorWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); | ||
42 | connect(&m_monitorWatcher, &QDBusServiceWatcher::serviceUnregistered, this, | 45 | connect(&m_monitorWatcher, &QDBusServiceWatcher::serviceUnregistered, this, | ||
Show All 28 Lines | 73 | #endif | |||
71 | break; | 74 | break; | ||
72 | } | 75 | } | ||
73 | QEventLoop loop; | 76 | QEventLoop loop; | ||
74 | connect(&process, &ExtractorProcess::done, &loop, &QEventLoop::quit); | 77 | connect(&process, &ExtractorProcess::done, &loop, &QEventLoop::quit); | ||
75 | 78 | | |||
76 | bool hadErrors = false; | 79 | bool hadErrors = false; | ||
77 | connect(&process, &ExtractorProcess::failed, &loop, [&hadErrors, &loop]() { hadErrors = true; loop.quit(); }); | 80 | connect(&process, &ExtractorProcess::failed, &loop, [&hadErrors, &loop]() { hadErrors = true; loop.quit(); }); | ||
78 | 81 | | |||
82 | uint batchStartCount = m_finishedCount; | ||||
83 | connect(&process, &ExtractorProcess::finishedIndexingFile, &loop, [this]() { m_finishedCount++; }); | ||||
84 | | ||||
79 | QElapsedTimer timer; | 85 | QElapsedTimer timer; | ||
80 | timer.start(); | 86 | timer.start(); | ||
81 | 87 | | |||
82 | process.index(idList); | 88 | process.index(idList); | ||
83 | loop.exec(); | 89 | loop.exec(); | ||
84 | batchSize = idList.size(); | 90 | batchSize = idList.size(); | ||
85 | 91 | | |||
86 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | 92 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | ||
87 | if (hadErrors && !m_stop.load()) { | 93 | if (hadErrors && !m_stop.load()) { | ||
88 | #else | 94 | #else | ||
89 | if (hadErrors && !m_stop.loadRelaxed()) { | 95 | if (hadErrors && !m_stop.loadRelaxed()) { | ||
90 | #endif | 96 | #endif | ||
91 | if (batchSize == 1) { | 97 | if (batchSize == 1) { | ||
92 | auto failedId = idList.first(); | 98 | auto failedId = idList.first(); | ||
93 | m_provider->markFailed(failedId); | 99 | m_provider->markFailed(failedId); | ||
94 | batchSize = m_batchSize; | 100 | batchSize = m_batchSize; | ||
95 | } else { | 101 | } else { | ||
96 | batchSize /= 2; | 102 | batchSize /= 2; | ||
97 | } | 103 | } | ||
104 | // reset to old value - nothing comitted | ||||
105 | m_finishedCount = batchStartCount; | ||||
98 | process.start(); | 106 | process.start(); | ||
99 | } else { | 107 | } else { | ||
100 | auto elapsed = timer.elapsed(); | 108 | auto elapsed = timer.elapsed(); | ||
101 | QMetaObject::invokeMethod(this, | 109 | QMetaObject::invokeMethod(this, | ||
102 | [this, elapsed, batchSize] { newBatchTime(elapsed, batchSize); }, | 110 | [this, elapsed, batchSize] { newBatchTime(elapsed, batchSize); }, | ||
103 | Qt::QueuedConnection); | 111 | Qt::QueuedConnection); | ||
104 | } | 112 | } | ||
105 | } | 113 | } | ||
Show All 39 Lines |