shared: IndexSyncer: Support cancellation

This commit is contained in:
Albert S. 2022-06-04 14:07:06 +02:00
父節點 7d9c883abd
當前提交 d7b93d11d8
共有 2 個文件被更改,包括 17 次插入3 次删除

查看文件

@ -34,10 +34,11 @@ void IndexSyncer::setPattern(QString pattern)
void IndexSyncer::sync()
{
this->stopToken.store(false, std::memory_order_relaxed);
FileSaver saver(*this->dbService);
QVector<FileData> files;
int offset = 0;
int limit = 1000;
int limit = 10000;
unsigned int processedRows = dbService->getFiles(files, pattern, offset, limit);
unsigned int totalUpdatesFilesCount = 0;
@ -49,6 +50,11 @@ void IndexSyncer::sync()
QVector<QString> filePathsToUpdate;
for(FileData &fileData : files)
{
if(processedRows % 100 == 0 && this->stopToken.load(std::memory_order_relaxed))
{
emit finished(totalUpdatesFilesCount, totalDeletedFilesCount, totalErroredFilesCount);
return;
}
QFileInfo fileInfo(fileData.absPath);
if(fileInfo.exists())
{
@ -109,10 +115,15 @@ void IndexSyncer::sync()
}
offset += limit;
files.clear();
processedRows = this->dbService->getFiles(files, pattern, offset, limit);
totalUpdatesFilesCount += updatedFilesCount;
processedRows = this->dbService->getFiles(files, pattern, offset, limit);
}
emit finished(totalUpdatesFilesCount, totalDeletedFilesCount, totalErroredFilesCount);
}
void IndexSyncer::cancel()
{
this->stopToken.store(true, std::memory_order_seq_cst);
}

查看文件

@ -13,11 +13,14 @@ class IndexSyncer : public QObject
bool verbose = false;
QString pattern;
std::atomic<bool> stopToken{false};
public:
IndexSyncer(SqliteDbService &dbService);
public slots:
void sync();
void cancel();
void setDryRun(bool dryRun);
void setVerbose(bool verbose);
void setKeepGoing(bool keepGoing);