From ff6e93fc1528298dc40e66d3a40a738fbce1b15a Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 3 Aug 2024 00:44:47 +0200 Subject: [PATCH] CollectionWatcher: Only start transaction with scan on startup Fixes #1469 --- src/collection/collectionwatcher.cpp | 34 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/collection/collectionwatcher.cpp b/src/collection/collectionwatcher.cpp index a3b7c75be..9b2946f78 100644 --- a/src/collection/collectionwatcher.cpp +++ b/src/collection/collectionwatcher.cpp @@ -421,22 +421,26 @@ void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const Colle last_scan_time_ = QDateTime::currentSecsSinceEpoch(); } else { - // We can do an incremental scan - looking at the mtimes of each subdirectory and only rescan if the directory has changed. - ScanTransaction transaction(this, dir.id, true, false, mark_songs_unavailable_); - QMap subdir_files_count; - const quint64 files_count = FilesCountForSubdirs(&transaction, subdirs, subdir_files_count); - transaction.SetKnownSubdirs(subdirs); - transaction.AddToProgressMax(files_count); - for (const CollectionSubdirectory &subdir : subdirs) { - if (stop_requested_ || abort_requested_) break; - - if (scan_on_startup_) ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction); - - if (monitor_) AddWatch(dir, subdir.path); + if (monitor_) { + for (const CollectionSubdirectory &subdir : subdirs) { + AddWatch(dir, subdir.path); + } + } + if (scan_on_startup_) { + // We can do an incremental scan - looking at the mtimes of each subdirectory and only rescan if the directory has changed. + ScanTransaction transaction(this, dir.id, true, false, mark_songs_unavailable_); + QMap subdir_files_count; + const quint64 files_count = FilesCountForSubdirs(&transaction, subdirs, subdir_files_count); + transaction.SetKnownSubdirs(subdirs); + transaction.AddToProgressMax(files_count); + for (const CollectionSubdirectory &subdir : subdirs) { + if (stop_requested_ || abort_requested_) break; + ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction); + } + if (!stop_requested_ && !abort_requested_) { + last_scan_time_ = QDateTime::currentSecsSinceEpoch(); + } } - - last_scan_time_ = QDateTime::currentSecsSinceEpoch(); - } emit CompilationsNeedUpdating();