Skip to content

Commit c9f5347

Browse files
authored
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
1 parent db7b126 commit c9f5347

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/tagstudio/core/library/refresh.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from tagstudio.core.library.alchemy.models import Entry
1818
from tagstudio.core.library.ignore import PATH_GLOB_FLAGS, Ignore, ignore_to_glob
1919
from tagstudio.core.utils.silent_subprocess import silent_run # pyright: ignore
20+
from tagstudio.core.utils.types import unwrap
2021

2122
logger = structlog.get_logger(__name__)
2223

@@ -30,24 +31,27 @@ class RefreshTracker:
3031
def files_count(self) -> int:
3132
return len(self.files_not_in_library)
3233

33-
def save_new_files(self):
34+
def save_new_files(self) -> Iterator[int]:
3435
"""Save the list of files that are not in the library."""
35-
if self.files_not_in_library:
36+
batch_size = 200
37+
38+
index = 0
39+
while index < len(self.files_not_in_library):
40+
yield index
41+
end = min(len(self.files_not_in_library), index + batch_size)
3642
entries = [
3743
Entry(
3844
path=entry_path,
39-
folder=self.library.folder, # pyright: ignore[reportArgumentType]
45+
folder=unwrap(self.library.folder),
4046
fields=[],
4147
date_added=dt.now(),
4248
)
43-
for entry_path in self.files_not_in_library
49+
for entry_path in self.files_not_in_library[index:end]
4450
]
4551
self.library.add_entries(entries)
46-
52+
index = end
4753
self.files_not_in_library = []
4854

49-
yield
50-
5155
def refresh_dir(self, library_dir: Path, force_internal_tools: bool = False) -> Iterator[int]:
5256
"""Scan a directory for files, and add those relative filenames to internal variables.
5357

src/tagstudio/qt/ts_qt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ def add_new_files_runnable(self, tracker: RefreshTracker):
10481048
pw.show()
10491049

10501050
iterator.value.connect(
1051-
lambda: (
1051+
lambda _count: (
10521052
pw.update_label(
10531053
Translations.format(
10541054
"entries.running.dialog.new_entries", total=f"{files_count:n}"

0 commit comments

Comments
 (0)