From c9f5347182eeb95e65f562f57709222a8ed9ac20 Mon Sep 17 00:00:00 2001 From: TheBobBobs <84781603+TheBobBobs@users.noreply.github.com> Date: Wed, 8 Oct 2025 04:16:43 +0000 Subject: [PATCH] fix: add periodic yield to save_new_files (#1040) * fix: add periodic yield to save_new_files * move refresh_dir.py * use variable for batch size --- src/tagstudio/core/library/refresh.py | 18 +++++++++++------- src/tagstudio/qt/ts_qt.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/tagstudio/core/library/refresh.py b/src/tagstudio/core/library/refresh.py index 1d455556..1b2115cd 100644 --- a/src/tagstudio/core/library/refresh.py +++ b/src/tagstudio/core/library/refresh.py @@ -17,6 +17,7 @@ from tagstudio.core.library.alchemy.library import Library from tagstudio.core.library.alchemy.models import Entry from tagstudio.core.library.ignore import PATH_GLOB_FLAGS, Ignore, ignore_to_glob from tagstudio.core.utils.silent_subprocess import silent_run # pyright: ignore +from tagstudio.core.utils.types import unwrap logger = structlog.get_logger(__name__) @@ -30,24 +31,27 @@ class RefreshTracker: def files_count(self) -> int: return len(self.files_not_in_library) - def save_new_files(self): + def save_new_files(self) -> Iterator[int]: """Save the list of files that are not in the library.""" - if self.files_not_in_library: + batch_size = 200 + + index = 0 + while index < len(self.files_not_in_library): + yield index + end = min(len(self.files_not_in_library), index + batch_size) entries = [ Entry( path=entry_path, - folder=self.library.folder, # pyright: ignore[reportArgumentType] + folder=unwrap(self.library.folder), fields=[], date_added=dt.now(), ) - for entry_path in self.files_not_in_library + for entry_path in self.files_not_in_library[index:end] ] self.library.add_entries(entries) - + index = end self.files_not_in_library = [] - yield - def refresh_dir(self, library_dir: Path, force_internal_tools: bool = False) -> Iterator[int]: """Scan a directory for files, and add those relative filenames to internal variables. diff --git a/src/tagstudio/qt/ts_qt.py b/src/tagstudio/qt/ts_qt.py index b2e20f49..8d7edde3 100644 --- a/src/tagstudio/qt/ts_qt.py +++ b/src/tagstudio/qt/ts_qt.py @@ -1048,7 +1048,7 @@ class QtDriver(DriverMixin, QObject): pw.show() iterator.value.connect( - lambda: ( + lambda _count: ( pw.update_label( Translations.format( "entries.running.dialog.new_entries", total=f"{files_count:n}"