fix(interface):开关索引后索引状态没有实时改变,stop和idle信号发送顺序有误.

This commit is contained in:
JunjieBai 2024-10-29 10:21:59 +08:00 committed by iaom
parent 04f65f5222
commit 479daeb699
3 changed files with 20 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -19,6 +19,7 @@
*/
#include "monitor.h"
#include <QMetaEnum>
#include <QApplication>
#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<IndexScheduler::IndexerState>();
Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state)));
QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
void Monitor::processUpdate(IndexType type, uint all, uint finished)