diff --git a/src/file/filecontentindexer.h b/src/file/filecontentindexer.h --- a/src/file/filecontentindexer.h +++ b/src/file/filecontentindexer.h @@ -63,7 +63,7 @@ Q_SCRIPTABLE void finishedIndexingFile(const QString& filePath); void done(); - void newBatchTime(uint time); + void newBatchTime(uint time, uint batchSize); private Q_SLOTS: void monitorClosed(const QString& service); diff --git a/src/file/filecontentindexer.cpp b/src/file/filecontentindexer.cpp --- a/src/file/filecontentindexer.cpp +++ b/src/file/filecontentindexer.cpp @@ -81,26 +81,29 @@ process.index(idList); loop.exec(); + batchSize = idList.size(); - // QDbus requires us to be in object creation thread (thread affinity) - // This signal is not even exported, and yet QDbus complains. QDbus bug? - QMetaObject::invokeMethod(this, "newBatchTime", Qt::QueuedConnection, Q_ARG(uint, timer.elapsed())); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) if (hadErrors && !m_stop.load()) { #else if (hadErrors && !m_stop.loadRelaxed()) { #endif - if (idList.size() == 1) { + if (batchSize == 1) { auto failedId = idList.first(); m_provider->markFailed(failedId); batchSize = m_batchSize; } else { - batchSize = idList.size() / 2; + batchSize /= 2; } process.start(); + } else { + auto elapsed = timer.elapsed(); + QMetaObject::invokeMethod(this, + [this, elapsed, batchSize] { newBatchTime(elapsed, batchSize); }, + Qt::QueuedConnection); } } - QMetaObject::invokeMethod(this, "done", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, &FileContentIndexer::done, Qt::QueuedConnection); } void FileContentIndexer::slotStartedIndexingFile(const QString& filePath) diff --git a/src/file/fileindexscheduler.cpp b/src/file/fileindexscheduler.cpp --- a/src/file/fileindexscheduler.cpp +++ b/src/file/fileindexscheduler.cpp @@ -44,7 +44,7 @@ , m_provider(db) , m_contentIndexer(nullptr) , m_indexerState(Startup) - , m_timeEstimator(config, this) + , m_timeEstimator(this) , m_checkUnindexedFiles(false) , m_checkStaleIndexEntries(false) , m_isGoingIdle(false) diff --git a/src/file/timeestimator.h b/src/file/timeestimator.h --- a/src/file/timeestimator.h +++ b/src/file/timeestimator.h @@ -40,20 +40,17 @@ { Q_OBJECT public: - explicit TimeEstimator(FileIndexerConfig* config, QObject* parent = nullptr); + explicit TimeEstimator(QObject* parent = nullptr); uint calculateTimeLeft(int filesLeft); public Q_SLOTS: - void handleNewBatchTime(uint time); + void handleNewBatchTime(uint time, uint batchSize); private: - uint m_batchTimeBuffer[BUFFER_SIZE]; + float m_batchTimeBuffer[BUFFER_SIZE]; int m_bufferIndex; bool m_estimateReady; - - FileIndexerConfig* m_config; - uint m_batchSize; }; } diff --git a/src/file/timeestimator.cpp b/src/file/timeestimator.cpp --- a/src/file/timeestimator.cpp +++ b/src/file/timeestimator.cpp @@ -27,12 +27,10 @@ using namespace Baloo; -TimeEstimator::TimeEstimator(FileIndexerConfig *config, QObject* parent) +TimeEstimator::TimeEstimator(QObject* parent) : QObject(parent) , m_bufferIndex(0) , m_estimateReady(false) - , m_config(config) - , m_batchSize(m_config->maxUncomittedFiles()) { } @@ -43,7 +41,6 @@ return 0; } - //TODO: We should probably make the batch size a global macro float totalTime = 0; float totalWeight = 0; @@ -57,20 +54,19 @@ } float weightedAverage = totalTime / totalWeight; - float batchesLeft = (float)filesLeft / (float)m_batchSize; - return weightedAverage * batchesLeft; + return weightedAverage * filesLeft; } -void TimeEstimator::handleNewBatchTime(uint time) +void TimeEstimator::handleNewBatchTime(uint time, uint batchSize) { // add the current batch time in place of the oldest batch time - m_batchTimeBuffer[m_bufferIndex] = time; + m_batchTimeBuffer[m_bufferIndex] = (float)time / batchSize; - if (!m_estimateReady && m_bufferIndex == BUFFER_SIZE - 1) { + m_bufferIndex = (m_bufferIndex + 1) % BUFFER_SIZE; + + if (!m_estimateReady && m_bufferIndex == 0) { // Buffer has been filled once. We are ready to estimate m_estimateReady = true; } - - m_bufferIndex = (m_bufferIndex + 1) % BUFFER_SIZE; }