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
This commit is contained in:
TheBobBobs
2025-10-08 04:16:43 +00:00
committed by GitHub
parent db7b126725
commit c9f5347182
2 changed files with 12 additions and 8 deletions

View File

@@ -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.

View File

@@ -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}"