Skip to content

Commit 2a97a5b

Browse files
authored
perf: add all new library entries at once (#737)
1 parent 14599e9 commit 2a97a5b

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

tagstudio/resources/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"entries.mirror.title": "Mirroring Entries",
2222
"entries.mirror.window_title": "Mirror Entries",
2323
"entries.mirror": "&Mirror",
24-
"entries.running.dialog.new_entries": "Adding {count}/{total} New File Entries...",
24+
"entries.running.dialog.new_entries": "Adding {total} New File Entries...",
2525
"entries.running.dialog.title": "Adding New File Entries",
2626
"entries.tags": "Tags",
2727
"entries.unlinked.delete_alt": "De&lete Unlinked Entries",

tagstudio/src/core/utils/refresh_dir.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,23 @@ class RefreshDirTracker:
3333
def files_count(self) -> int:
3434
return len(self.files_not_in_library)
3535

36-
def save_new_files(self) -> Iterator[int]:
36+
def save_new_files(self):
3737
"""Save the list of files that are not in the library."""
38-
if not self.files_not_in_library:
39-
yield 0
40-
41-
for idx, entry_path in enumerate(self.files_not_in_library):
42-
self.library.add_entries(
43-
[
44-
Entry(
45-
path=entry_path,
46-
folder=self.library.folder,
47-
fields=[],
48-
)
49-
]
50-
)
51-
yield idx
38+
if self.files_not_in_library:
39+
entries = [
40+
Entry(
41+
path=entry_path,
42+
folder=self.library.folder,
43+
fields=[],
44+
)
45+
for entry_path in self.files_not_in_library
46+
]
47+
self.library.add_entries(entries)
5248

5349
self.files_not_in_library = []
5450

51+
yield
52+
5553
def refresh_dir(self, lib_path: Path) -> Iterator[int]:
5654
"""Scan a directory for files, and add those relative filenames to internal variables."""
5755
if self.library.library_dir is None:

tagstudio/src/qt/ts_qt.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ def add_new_files_callback(self):
815815
"library.refresh.scanning.plural"
816816
if x + 1 != 1
817817
else "library.refresh.scanning.singular",
818-
searched_count=x + 1,
819-
found_count=tracker.files_count,
818+
searched_count=f"{x+1:n}",
819+
found_count=f"{tracker.files_count:n}",
820820
)
821821
),
822822
)
@@ -842,20 +842,19 @@ def add_new_files_runnable(self, tracker: RefreshDirTracker):
842842
pw = ProgressWidget(
843843
cancel_button_text=None,
844844
minimum=0,
845-
maximum=files_count,
845+
maximum=0,
846846
)
847847
Translations.translate_with_setter(pw.setWindowTitle, "entries.running.dialog.title")
848848
Translations.translate_with_setter(
849-
pw.update_label, "entries.running.dialog.new_entries", count=1, total=files_count
849+
pw.update_label, "entries.running.dialog.new_entries", total=f"{files_count:n}"
850850
)
851851
pw.show()
852852

853853
iterator.value.connect(
854-
lambda x: (
855-
pw.update_progress(x + 1),
854+
lambda: (
856855
pw.update_label(
857856
Translations.translate_formatted(
858-
"entries.running.dialog.new_entries", count=x + 1, total=files_count
857+
"entries.running.dialog.new_entries", total=f"{files_count:n}"
859858
)
860859
),
861860
)

0 commit comments

Comments
 (0)