Only refresh library if some book has been added/removed in monitor dir

This change leads to less refreshes if the monitor directory is same as download directory
Earlier, while downloading a file, it would send many refresh signals to file watcher leading to a bad user experience
This commit is contained in:
Nikhil Tanwar 2022-03-03 12:26:06 +05:30 committed by Emmanuel Engelhart
parent 52a96cdf23
commit 2370019491
No known key found for this signature in database
GPG Key ID: 120B30D020B553D3

View File

@ -157,16 +157,19 @@ void Library::loadMonitorDir(QString monitorDir)
QSet<QString> oldDir = QSet<QString>::fromList(oldDirEntries);
QStringList addedZims = (newDir - oldDir).values();
QStringList removedZims = (oldDir - newDir).values();
setMonitorDirZims(newDir.values());
auto manipulator = LibraryManipulator(this);
auto manager = kiwix::Manager(&manipulator);
bool needsRefresh = !removedZims.empty();
for (auto book : addedZims) {
manager.addBookFromPath(book.toStdString());
needsRefresh |= manager.addBookFromPath(book.toStdString());
}
for (auto bookPath : removedZims) {
removeBookFromLibraryById(QString::fromStdString(m_library.getBookByPath(bookPath.toStdString()).getId()));
}
emit(booksChanged());
if (needsRefresh) {
setMonitorDirZims(newDir.values());
emit(booksChanged());
}
}
void Library::asyncLoadMonitorDir(QString dir)