shared: IndexSyncer: Support cancellation
This commit is contained in:
parent
7d9c883abd
commit
d7b93d11d8
@ -34,10 +34,11 @@ void IndexSyncer::setPattern(QString pattern)
|
|||||||
|
|
||||||
void IndexSyncer::sync()
|
void IndexSyncer::sync()
|
||||||
{
|
{
|
||||||
|
this->stopToken.store(false, std::memory_order_relaxed);
|
||||||
FileSaver saver(*this->dbService);
|
FileSaver saver(*this->dbService);
|
||||||
QVector<FileData> files;
|
QVector<FileData> files;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int limit = 1000;
|
int limit = 10000;
|
||||||
unsigned int processedRows = dbService->getFiles(files, pattern, offset, limit);
|
unsigned int processedRows = dbService->getFiles(files, pattern, offset, limit);
|
||||||
|
|
||||||
unsigned int totalUpdatesFilesCount = 0;
|
unsigned int totalUpdatesFilesCount = 0;
|
||||||
@ -49,6 +50,11 @@ void IndexSyncer::sync()
|
|||||||
QVector<QString> filePathsToUpdate;
|
QVector<QString> filePathsToUpdate;
|
||||||
for(FileData &fileData : files)
|
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);
|
QFileInfo fileInfo(fileData.absPath);
|
||||||
if(fileInfo.exists())
|
if(fileInfo.exists())
|
||||||
{
|
{
|
||||||
@ -109,10 +115,15 @@ void IndexSyncer::sync()
|
|||||||
}
|
}
|
||||||
offset += limit;
|
offset += limit;
|
||||||
files.clear();
|
files.clear();
|
||||||
processedRows = this->dbService->getFiles(files, pattern, offset, limit);
|
|
||||||
|
|
||||||
totalUpdatesFilesCount += updatedFilesCount;
|
totalUpdatesFilesCount += updatedFilesCount;
|
||||||
|
|
||||||
|
processedRows = this->dbService->getFiles(files, pattern, offset, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit finished(totalUpdatesFilesCount, totalDeletedFilesCount, totalErroredFilesCount);
|
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;
|
bool verbose = false;
|
||||||
QString pattern;
|
QString pattern;
|
||||||
|
|
||||||
|
std::atomic<bool> stopToken{false};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IndexSyncer(SqliteDbService &dbService);
|
IndexSyncer(SqliteDbService &dbService);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sync();
|
void sync();
|
||||||
|
void cancel();
|
||||||
void setDryRun(bool dryRun);
|
void setDryRun(bool dryRun);
|
||||||
void setVerbose(bool verbose);
|
void setVerbose(bool verbose);
|
||||||
void setKeepGoing(bool keepGoing);
|
void setKeepGoing(bool keepGoing);
|
||||||
|
Loading…
Reference in New Issue
Block a user