fix(index):修复了错误的开关索引控制逻辑;

修复了关闭基本索引导致内容索引监听丢失的问题
This commit is contained in:
iaom 2023-09-05 18:41:28 +08:00
parent d48c6e8823
commit 73604c0dfe
4 changed files with 17 additions and 19 deletions

View File

@ -185,7 +185,7 @@ void BatchIndexer::basicIndex()
void BatchIndexer::contentIndex() void BatchIndexer::contentIndex()
{ {
qDebug() << "Begin content index"; qDebug() << "Begin content index";
if(m_indexStop->LOAD) { if(m_contentIndexStop->LOAD) {
qDebug() << "Index stopped, abort content index."; qDebug() << "Index stopped, abort content index.";
return; return;
} }
@ -252,7 +252,7 @@ void BatchIndexer::contentIndex()
uint batchSize = 0; uint batchSize = 0;
uint finishNum = 0; uint finishNum = 0;
for (QString path : filesNeedIndex) { for (QString path : filesNeedIndex) {
if(m_indexStop->LOAD) { if(m_contentIndexStop->LOAD) {
qDebug() << "Index stopped, interrupt content index."; qDebug() << "Index stopped, interrupt content index.";
filesNeedIndex.clear(); filesNeedIndex.clear();
filesNeedOCRIndex.clear(); filesNeedOCRIndex.clear();
@ -290,7 +290,7 @@ void BatchIndexer::contentIndex()
batchSize = 0; batchSize = 0;
int ocrFinishNum = 0; int ocrFinishNum = 0;
for(QString path : filesNeedOCRIndex) { for(QString path : filesNeedOCRIndex) {
if(m_indexStop->LOAD) { if(m_contentIndexStop->LOAD) {
qDebug() << "Index stopped, interrupt content index."; qDebug() << "Index stopped, interrupt content index.";
filesNeedOCRIndex.clear(); filesNeedOCRIndex.clear();
return; return;

View File

@ -118,7 +118,7 @@ IndexScheduler::IndexerState IndexScheduler::getIndexState()
void IndexScheduler::start(BatchIndexer::Targets target) void IndexScheduler::start(BatchIndexer::Targets target)
{ {
qDebug() << "Index scheduler start."; qDebug() << "Index scheduler start." << target;
//检查是否有任务未完成 //检查是否有任务未完成
BatchIndexer::Targets tmpTargets = BatchIndexer::Target::None; BatchIndexer::Targets tmpTargets = BatchIndexer::Target::None;
if(target & BatchIndexer::Basic) { if(target & BatchIndexer::Basic) {
@ -141,10 +141,10 @@ void IndexScheduler::start(BatchIndexer::Targets target)
} }
//打开异步控制开关 //打开异步控制开关
if(tmpTargets & BatchIndexer::Basic) { if(target & BatchIndexer::Basic) {
m_indexStop.fetchAndStoreRelaxed(0); m_indexStop.fetchAndStoreRelaxed(0);
} }
if(tmpTargets & BatchIndexer::Content) { if(target & BatchIndexer::Content) {
m_contentIndexStop.fetchAndStoreRelaxed(0); m_contentIndexStop.fetchAndStoreRelaxed(0);
} }
//将索引调度器状态设置为运行中 //将索引调度器状态设置为运行中
@ -253,7 +253,7 @@ void IndexScheduler::updateIndex(const QVector<PendingFile> &files)
qDebug() << "updateIndex====="; qDebug() << "updateIndex=====";
m_updateFinished = false; m_updateFinished = false;
m_state = Running; m_state = Running;
IndexUpdater *updateJob = new IndexUpdater(files, m_indexStop); IndexUpdater *updateJob = new IndexUpdater(files, m_indexStop, m_contentIndexStop);
connect(updateJob, &IndexUpdater::done, this, &IndexScheduler::updateFinished, Qt::QueuedConnection); connect(updateJob, &IndexUpdater::done, this, &IndexScheduler::updateFinished, Qt::QueuedConnection);
m_threadPool.start(updateJob); m_threadPool.start(updateJob);
} }

View File

@ -27,16 +27,17 @@
#include "file-utils.h" #include "file-utils.h"
#include "compatible-define.h" #include "compatible-define.h"
using namespace UkuiSearch; using namespace UkuiSearch;
IndexUpdater::IndexUpdater(const QVector<PendingFile>& files, QAtomicInt &stop) IndexUpdater::IndexUpdater(const QVector<PendingFile>& files, QAtomicInt& indexstop, QAtomicInt& contentIndexstop)
: m_cache(files), : m_cache(files),
m_stop(&stop) m_indexStop(&indexstop),
m_contentIndexStop(&contentIndexstop)
{ {
} }
void IndexUpdater::updateIndex() void IndexUpdater::updateIndex()
{ {
//fix me: How should I delete metadata of files below a folder //fix me: How should I delete metadata of files below a folder
//which has been deleted(When a file watcher signal comes which only contains folder info)? //which has been deleted(When a file watcher signal comes which only contains folder info)?
if(FileIndexerConfig::getInstance()->isFileIndexEnable()) { if(FileIndexerConfig::getInstance()->isFileIndexEnable() && !m_indexStop->LOAD) {
WritableDatabase basicDb(DataBaseType::Basic); WritableDatabase basicDb(DataBaseType::Basic);
if(!basicDb.open()) { if(!basicDb.open()) {
qWarning() << "Basic db open failed, fail to update index"; qWarning() << "Basic db open failed, fail to update index";
@ -62,11 +63,7 @@ void IndexUpdater::updateIndex()
basicDb.commit(); basicDb.commit();
qDebug() << "===finish update basic index==="; qDebug() << "===finish update basic index===";
} }
if(FileIndexerConfig::getInstance()->isContentIndexEnable()) { if(FileIndexerConfig::getInstance()->isContentIndexEnable() && !m_contentIndexStop->LOAD) {
if(m_stop->LOAD) {
qDebug() << "Index stopped, abort update content index.";
return;
}
WritableDatabase contentDb(DataBaseType::Content); WritableDatabase contentDb(DataBaseType::Content);
if(!contentDb.open()) { if(!contentDb.open()) {
qWarning() << "Content db open failed, fail to update index"; qWarning() << "Content db open failed, fail to update index";
@ -111,7 +108,7 @@ void IndexUpdater::updateIndex()
qDebug() << "30 finished."; qDebug() << "30 finished.";
size = 0; size = 0;
} }
if(m_stop->LOAD) { if(m_contentIndexStop->LOAD) {
qDebug() << "Index stopped, content index update interrupted"; qDebug() << "Index stopped, content index update interrupted";
m_cache.clear(); m_cache.clear();
m_cache.shrink_to_fit(); m_cache.shrink_to_fit();

View File

@ -31,7 +31,7 @@ class IndexUpdater : public QObject, public QRunnable
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit IndexUpdater(const QVector<PendingFile>& files, QAtomicInt& stop); explicit IndexUpdater(const QVector<PendingFile>& files, QAtomicInt& indexstop, QAtomicInt& contentIndexstop);
void run() override; void run() override;
Q_SIGNALS: Q_SIGNALS:
@ -41,7 +41,8 @@ private:
void updateIndex(); void updateIndex();
QVector<PendingFile> m_cache; QVector<PendingFile> m_cache;
QAtomicInt *m_stop = nullptr; QAtomicInt *m_contentIndexStop = nullptr;
QAtomicInt *m_indexStop = nullptr;
}; };
} }
#endif // INDEXUPDATER_H #endif // INDEXUPDATER_H