refactor: look regions up through lookup_slot

lookup_regions walked the destination, its suffixes and the name
again. It now projects the entry lookup_slot finds. No behavior change.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:26 +01:00
1 parent 8f153e2b89
commit 187d9ea5e4
1 file changed
+5 -13
+5 -13
View File
@@ -72,20 +72,12 @@ def build_region_index(profiles: dict) -> dict[str, dict]:
def lookup_regions(index: dict[str, dict], destination: str, name: str) -> set[str]:
"""Look a candidate file up in the region index.
Tries the full destination, then progressively shorter path suffixes, then
the bare name. Suffix matching bridges a platform entry whose destination
carries an extra prefix to the profile entry that declares the region.
Tried in lookup_slot's order: the full destination, then progressively
shorter path suffixes, then the bare name. Suffix matching bridges a
platform entry whose destination carries an extra prefix to the profile
entry that declares the region.
"""
if destination:
entry = index.get(destination)
if entry:
return set() if entry.get("has_untagged") else set(entry["regions"])
parts = destination.split("/")
for i in range(1, len(parts)):
entry = index.get("/".join(parts[i:]))
if entry:
return set() if entry.get("has_untagged") else set(entry["regions"])
entry = index.get(name)
entry = lookup_slot(index, destination, name)
if not entry or entry.get("has_untagged"):
return set()
return set(entry["regions"])