/* * Copyright (C) 2022, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: iaom * */ #include "index-updater.h" #include #include "writable-database.h" #include "basic-indexer.h" #include "file-indexer-config.h" #include "file-content-indexer.h" #include "common.h" #include "file-utils.h" using namespace UkuiSearch; IndexUpdater::IndexUpdater(const QVector& files, QAtomicInt &stop) : m_cache(files), m_stop(&stop) { } void IndexUpdater::UpdateIndex() { if(FileIndexerConfig::getInstance()->isFileIndexEnable()) { WritableDatabase basicDb(DataBaseType::Basic); if(!basicDb.open()) { qWarning() << "Basic db open failed, fail to update index"; return; } qDebug() << "===update basic index==="; for(PendingFile file : m_cache) { if(file.shouldRemoveIndex()) { qDebug() << "| remove:" <isContentIndexEnable()) { if(m_stop->load()) { qDebug() << "Index stopped, abort update content index."; return; } WritableDatabase contentDb(DataBaseType::Content); if(!contentDb.open()) { qWarning() << "Content db open failed, fail to update index"; return; } QMap suffixMap = targetFileTypeMap; //ocr if(FileIndexerConfig::getInstance()->isOCREnable()) { suffixMap.unite(targetPhotographTypeMap); } qDebug() << "===update content index==="; int size = 0; for(PendingFile file : m_cache) { QString suffix = QFileInfo(file.path()).suffix(); if(file.shouldRemoveIndex()) { qDebug() << "| remove:" <= 30) { contentDb.commit(); qDebug() << "30 finished."; size = 0; } if(m_stop->load()) { qDebug() << "Index stopped, content index update interrupted"; m_cache.clear(); m_cache.shrink_to_fit(); malloc_trim(0); return; } } contentDb.commit(); qDebug() << "===finish update content index==="; } m_cache.clear(); m_cache.shrink_to_fit(); malloc_trim(0); Q_EMIT done(); } void IndexUpdater::run() { UpdateIndex(); }