mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 12:52:19 +01:00
perf(scan): drop quadratic file exclusion check
exclude_single_files collected every excluded name into a list, then filtered the input against it with `f not in excluded_files`. That membership test rescans the list once per file, so a platform folder holding tens of thousands of loose files spends most of the call in list scans rather than pattern matching. Decide per file in a single pass instead. Behavior is unchanged, including for duplicate file names. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TLTDjv3niosCXZWtjKELK2
This commit is contained in:
@@ -271,24 +271,23 @@ class FSHandler:
|
||||
cnfg = cm.get_config()
|
||||
excluded_extensions = cnfg.EXCLUDED_SINGLE_EXT
|
||||
excluded_names = cnfg.EXCLUDED_SINGLE_FILES
|
||||
excluded_files: list[str] = []
|
||||
|
||||
for file_name in files:
|
||||
file_name_lower = file_name.lower()
|
||||
|
||||
def is_excluded(file_name: str) -> bool:
|
||||
# Check whether the filename ends with any excluded extension entry.
|
||||
if any(file_name_lower.endswith("." + ext) for ext in excluded_extensions):
|
||||
excluded_files.append(file_name)
|
||||
continue
|
||||
if any(
|
||||
file_name.lower().endswith("." + ext) for ext in excluded_extensions
|
||||
):
|
||||
return True
|
||||
|
||||
# Check if the file name matches a pattern in the excluded list.
|
||||
if file_name in excluded_names or any(
|
||||
return file_name in excluded_names or any(
|
||||
fnmatch.fnmatch(file_name, name) for name in excluded_names
|
||||
):
|
||||
excluded_files.append(file_name)
|
||||
)
|
||||
|
||||
# Return files that are not in the filtered list.
|
||||
return [f for f in files if f not in excluded_files]
|
||||
# Deciding per file keeps this linear. Collecting the exclusions first and
|
||||
# then filtering against that list rescans it once per file, which gets
|
||||
# expensive on platforms holding tens of thousands of files.
|
||||
return [f for f in files if not is_excluded(f)]
|
||||
|
||||
async def make_directory(self, path: str) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user