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

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

View File

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

View File

@ -118,7 +118,7 @@ IndexScheduler::IndexerState IndexScheduler::getIndexState()
void IndexScheduler::start(BatchIndexer::Targets target)
{
qDebug() << "Index scheduler start.";
qDebug() << "Index scheduler start." << target;
//检查是否有任务未完成
BatchIndexer::Targets tmpTargets = BatchIndexer::Target::None;
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);
}
if(tmpTargets & BatchIndexer::Content) {
if(target & BatchIndexer::Content) {
m_contentIndexStop.fetchAndStoreRelaxed(0);
}
//将索引调度器状态设置为运行中
@ -253,7 +253,7 @@ void IndexScheduler::updateIndex(const QVector<PendingFile> &files)
qDebug() << "updateIndex=====";
m_updateFinished = false;
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);
m_threadPool.start(updateJob);
}

View File

@ -27,16 +27,17 @@
#include "file-utils.h"
#include "compatible-define.h"
using namespace UkuiSearch;
IndexUpdater::IndexUpdater(const QVector<PendingFile>& files, QAtomicInt &stop)
: m_cache(files),
m_stop(&stop)
IndexUpdater::IndexUpdater(const QVector<PendingFile>& files, QAtomicInt& indexstop, QAtomicInt& contentIndexstop)
: m_cache(files),
m_indexStop(&indexstop),
m_contentIndexStop(&contentIndexstop)
{
}
void IndexUpdater::updateIndex()
{
//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)?
if(FileIndexerConfig::getInstance()->isFileIndexEnable()) {
if(FileIndexerConfig::getInstance()->isFileIndexEnable() && !m_indexStop->LOAD) {
WritableDatabase basicDb(DataBaseType::Basic);
if(!basicDb.open()) {
qWarning() << "Basic db open failed, fail to update index";
@ -62,11 +63,7 @@ void IndexUpdater::updateIndex()
basicDb.commit();
qDebug() << "===finish update basic index===";
}
if(FileIndexerConfig::getInstance()->isContentIndexEnable()) {
if(m_stop->LOAD) {
qDebug() << "Index stopped, abort update content index.";
return;
}
if(FileIndexerConfig::getInstance()->isContentIndexEnable() && !m_contentIndexStop->LOAD) {
WritableDatabase contentDb(DataBaseType::Content);
if(!contentDb.open()) {
qWarning() << "Content db open failed, fail to update index";
@ -111,7 +108,7 @@ void IndexUpdater::updateIndex()
qDebug() << "30 finished.";
size = 0;
}
if(m_stop->LOAD) {
if(m_contentIndexStop->LOAD) {
qDebug() << "Index stopped, content index update interrupted";
m_cache.clear();
m_cache.shrink_to_fit();

View File

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