Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/tagstudio/core/library/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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__)

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

Expand Down
2 changes: 1 addition & 1 deletion src/tagstudio/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ def add_new_files_runnable(self, tracker: RefreshTracker):
pw.show()

iterator.value.connect(
lambda: (
lambda _count: (
pw.update_label(
Translations.format(
"entries.running.dialog.new_entries", total=f"{files_count:n}"
Expand Down