Skip to content

Commit 334b160

Browse files
committed
fix: avoid superfluous calls to os.walk when relinking missing files (#610)
1 parent 262893a commit 334b160

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tagstudio/src/core/library/json/library.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ class Library:
304304
def __init__(self) -> None:
305305
# Library Info =========================================================
306306
self.library_dir: Path = None
307+
# Cached result of os.walk when relinking library files
308+
self._library_file_cache: list[(string, list[string], list[string])] = None
307309

308310
# Entries ==============================================================
309311
# List of every Entry object.
@@ -1092,6 +1094,7 @@ def fix_missing_files(self):
10921094
yield (i, True)
10931095
else:
10941096
yield (i, False)
1097+
self._library_file_cache = None
10951098

10961099
# self._purge_empty_missing_entries()
10971100

@@ -1124,9 +1127,12 @@ def _match_missing_file(self, file: str) -> list[Path]:
11241127

11251128
matches = []
11261129

1130+
if self._library_file_cache is None:
1131+
self._library_file_cache = list(os.walk(self.library_dir))
1132+
11271133
# for file in self.missing_files:
11281134
path = Path(file)
1129-
for root, dirs, files in os.walk(self.library_dir):
1135+
for root, dirs, files in self._library_file_cache:
11301136
for f in files:
11311137
# print(f'{tail} --- {f}')
11321138
if path.name == f and "$recycle.bin" not in str(root).lower():

0 commit comments

Comments
 (0)