parent
d48c6e8823
commit
73604c0dfe
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue