refactor: build the entry_source index once

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:01:19 +01:00
1 parent 90fad87b97
commit b4075bf1ad
2 files changed
+20 -31

No files matched your search

+18 -16
View File
@@ -596,6 +596,23 @@ def entry_target(entry: dict, files: list[dict]) -> tuple[dict, str]:
return with_archive_members(entry, files), entry.get("path") or ""
def entry_index(db: dict, data_names: set[str] | None) -> dict:
"""The collection indexes entry_source reads, one build for every caller."""
indexes = db.get("indexes", {})
by_name = indexes.get("by_name", {})
return {
"by_name": by_name,
"by_name_lower": {k.lower(): k for k in by_name},
"by_md5": indexes.get("by_md5", {}),
"by_crc32": indexes.get("by_crc32", {}),
"by_sha256": indexes.get("by_sha256", {}),
"by_path_suffix": indexes.get("by_path_suffix", {}),
"db_files": db.get("files", {}),
"data_names": data_names,
"bios_dir": db.get("bios_dir"),
}
def entry_source(f: dict, index: dict) -> str | None:
"""Where the collection holds a profile entry, or None.
@@ -1399,28 +1416,13 @@ def cross_reference(
launcher_layer = scope.get("launcher_layer")
declared_contents = scope.get("declared_contents")
platform_data_dirs = platform_data_dirs or {}
by_name = db.get("indexes", {}).get("by_name", {})
by_name_lower = {k.lower(): k for k in by_name}
by_md5 = db.get("indexes", {}).get("by_md5", {})
by_crc32 = db.get("indexes", {}).get("by_crc32", {})
by_sha256 = db.get("indexes", {}).get("by_sha256", {})
by_path_suffix = db.get("indexes", {}).get("by_path_suffix", {})
db_files = db.get("files", {})
report: dict[str, dict] = {}
index = {
"by_name": by_name,
"by_name_lower": by_name_lower,
"by_md5": by_md5,
"by_crc32": by_crc32,
"by_sha256": by_sha256,
"by_path_suffix": by_path_suffix,
"db_files": db_files,
"data_names": data_names,
**entry_index(db, data_names),
"all_declared": all_declared,
"folded_slots": folded_slots,
"declared_contents": declared_contents,
"bios_dir": db.get("bios_dir"),
"launcher_candidates": [] if launcher_layer else None,
}
for emu_name, profile in profiles.items():
+2 -15
View File
@@ -80,22 +80,9 @@ def availability_check(
missing while the gap report called it held would describe a
different collection on two pages of the same site.
"""
from packs.crossref import entry_source
from packs.crossref import entry_index, entry_source
by_name = db.get("indexes", {}).get("by_name", {})
by_name_lower = {k.lower(): k for k in by_name}
by_path_suffix = db.get("indexes", {}).get("by_path_suffix", {})
index = {
"by_name": by_name,
"by_name_lower": by_name_lower,
"by_path_suffix": by_path_suffix,
"by_md5": db.get("indexes", {}).get("by_md5", {}),
"by_sha256": db.get("indexes", {}).get("by_sha256", {}),
"by_crc32": db.get("indexes", {}).get("by_crc32", {}),
"db_files": db.get("files", {}),
"data_names": data_names,
}
index = entry_index(db, data_names)
def _file_available(f: dict) -> bool:
"""Check if a file is available using the same resolution as cross_reference."""