From 7495a5bf15d4f8eb32ce5083074281fdabb7235f Mon Sep 17 00:00:00 2001 From: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> Date: Sun, 26 Jan 2025 01:43:29 -0800 Subject: [PATCH] perf: add all new library entries at once --- tagstudio/resources/translations/en.json | 2 +- tagstudio/src/core/utils/refresh_dir.py | 28 +++++++++++------------- tagstudio/src/qt/ts_qt.py | 13 +++++------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/tagstudio/resources/translations/en.json b/tagstudio/resources/translations/en.json index 921cb6713..5feae7220 100644 --- a/tagstudio/resources/translations/en.json +++ b/tagstudio/resources/translations/en.json @@ -20,7 +20,7 @@ "entries.mirror.title": "Mirroring Entries", "entries.mirror.window_title": "Mirror Entries", "entries.mirror": "&Mirror", - "entries.running.dialog.new_entries": "Adding {count}/{total} New File Entries...", + "entries.running.dialog.new_entries": "Adding {total} New File Entries...", "entries.running.dialog.title": "Adding New File Entries", "entries.tags": "Tags", "entries.unlinked.delete_alt": "De&lete Unlinked Entries", diff --git a/tagstudio/src/core/utils/refresh_dir.py b/tagstudio/src/core/utils/refresh_dir.py index 8bfd34566..a398f06fe 100644 --- a/tagstudio/src/core/utils/refresh_dir.py +++ b/tagstudio/src/core/utils/refresh_dir.py @@ -33,25 +33,23 @@ class RefreshDirTracker: def files_count(self) -> int: return len(self.files_not_in_library) - def save_new_files(self) -> Iterator[int]: + def save_new_files(self): """Save the list of files that are not in the library.""" - if not self.files_not_in_library: - yield 0 - - for idx, entry_path in enumerate(self.files_not_in_library): - self.library.add_entries( - [ - Entry( - path=entry_path, - folder=self.library.folder, - fields=[], - ) - ] - ) - yield idx + if self.files_not_in_library: + entries = [ + Entry( + path=entry_path, + folder=self.library.folder, + fields=[], + ) + for entry_path in self.files_not_in_library + ] + self.library.add_entries(entries) self.files_not_in_library = [] + yield + def refresh_dir(self, lib_path: Path) -> Iterator[int]: """Scan a directory for files, and add those relative filenames to internal variables.""" if self.library.library_dir is None: diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 8d0f41bb0..e4987d1af 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -786,8 +786,8 @@ def add_new_files_callback(self): "library.refresh.scanning.plural" if x + 1 != 1 else "library.refresh.scanning.singular", - searched_count=x + 1, - found_count=tracker.files_count, + searched_count=f"{x+1:n}", + found_count=f"{tracker.files_count:n}", ) ), ) @@ -813,20 +813,19 @@ def add_new_files_runnable(self, tracker: RefreshDirTracker): pw = ProgressWidget( cancel_button_text=None, minimum=0, - maximum=files_count, + maximum=0, ) Translations.translate_with_setter(pw.setWindowTitle, "entries.running.dialog.title") Translations.translate_with_setter( - pw.update_label, "entries.running.dialog.new_entries", count=1, total=files_count + pw.update_label, "entries.running.dialog.new_entries", total=f"{files_count:n}" ) pw.show() iterator.value.connect( - lambda x: ( - pw.update_progress(x + 1), + lambda: ( pw.update_label( Translations.translate_formatted( - "entries.running.dialog.new_entries", count=x + 1, total=files_count + "entries.running.dialog.new_entries", total=f"{files_count:n}" ) ), )