From ef985af55f6007ad5e82148ff1655246ac9e4b18 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Tue, 29 Oct 2024 10:21:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(interface):=E5=BC=80=E5=85=B3=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=90=8E=E7=B4=A2=E5=BC=95=E7=8A=B6=E6=80=81=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=AE=9E=E6=97=B6=E6=94=B9=E5=8F=98=EF=BC=8Cstop?= =?UTF-8?q?=E5=92=8Cidle=E4=BF=A1=E5=8F=B7=E5=8F=91=E9=80=81=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E6=9C=89=E8=AF=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/batch-indexer.cpp | 22 ++++++++++++++++------ libsearch/index/index-scheduler.cpp | 4 ++-- ukui-search-service/monitor.cpp | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libsearch/index/batch-indexer.cpp b/libsearch/index/batch-indexer.cpp index ea3e6e2..5828722 100644 --- a/libsearch/index/batch-indexer.cpp +++ b/libsearch/index/batch-indexer.cpp @@ -119,6 +119,11 @@ void BatchIndexer::fetch() dir.setPath(bfs.dequeue()); list = dir.entryInfoList(); for(const auto& i : list) { + if(m_indexStop->LOAD && m_contentIndexStop->LOAD && m_contentIndexOcrStop->LOAD && m_aiIndexStop->LOAD) { + qDebug() << "Index stopped, abort index from traversal."; + m_cache.clear(); + return; + } bool isBlocked = false; for(const QString &path : tmpList) { if(i.absoluteFilePath() == path) { @@ -142,6 +147,11 @@ void BatchIndexer::fetch() void BatchIndexer::basicIndex() { qDebug() << "Begin basic index"; + if(m_indexStop->LOAD) { + qDebug() << "Index stopped, abort basic index."; + return; + } + WritableDatabase basicDb(DataBaseType::Basic); if(!basicDb.open()) { qWarning() << "Basic db open failed, fail to run basic index!"; @@ -183,6 +193,12 @@ void BatchIndexer::basicIndex() uint batchSize = 0; uint finishNum = 0; for (const QString& path: filesNeedIndex) { + if(m_indexStop->LOAD) { + basicDb.commit(); + qDebug() << "Index stopped, interrupt basic index."; + filesNeedIndex.clear(); + return; + } BasicIndexer indexer(path); if(indexer.index()) { basicDb.addDocument(indexer.document()); @@ -193,12 +209,6 @@ void BatchIndexer::basicIndex() qDebug() << finishNum << "of" << allSize <<"finished."; basicDb.commit(); Q_EMIT progress(IndexType::Basic, allSize, finishNum); - //文件名索引很快 - if(m_indexStop->LOAD) { - qDebug() << "Index stopped, abort basic index."; - filesNeedIndex.clear(); - return; - } batchSize = 0; } } diff --git a/libsearch/index/index-scheduler.cpp b/libsearch/index/index-scheduler.cpp index 5837e66..c9c06e9 100644 --- a/libsearch/index/index-scheduler.cpp +++ b/libsearch/index/index-scheduler.cpp @@ -360,7 +360,7 @@ void IndexScheduler::batchIndexerFinished(BatchIndexer::WorkMode mode, BatchInde if(mode == BatchIndexer::WorkMode::Add) { m_addNewPathPendingWorkCount--; } - if(isIdle()) { + if (isIdle() && m_state != Stop) { m_state = Idle; Q_EMIT stateChange(m_state); } @@ -369,7 +369,7 @@ void IndexScheduler::batchIndexerFinished(BatchIndexer::WorkMode mode, BatchInde void IndexScheduler::updateFinished() { m_updatePendingWorkCount--; - if(isIdle()) { + if (isIdle() && m_state != Stop) { m_state = Idle; Q_EMIT stateChange(m_state); } diff --git a/ukui-search-service/monitor.cpp b/ukui-search-service/monitor.cpp index e2a9e55..9627679 100644 --- a/ukui-search-service/monitor.cpp +++ b/ukui-search-service/monitor.cpp @@ -19,6 +19,7 @@ */ #include "monitor.h" #include +#include #include "file-indexer-config.h" using namespace UkuiSearch; Monitor::Monitor(IndexScheduler *scheduler, QObject *parent) : MonitorSource(parent), @@ -163,6 +164,7 @@ void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state) } QMetaEnum metaEnum = QMetaEnum::fromType(); Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state))); + QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } void Monitor::processUpdate(IndexType type, uint all, uint finished)