fix: address 4 quality review findings — flush_batch order, batch finally guard, cache copy, LIMIT=0 fallthrough

This commit is contained in:
2026-06-16 16:59:43 +00:00
parent 817fa17e41
commit f3622b8d41
3 changed files with 218 additions and 214 deletions
+2
View File
@@ -368,6 +368,7 @@ def upload_to_frigate(jobs: list[dict]) -> None:
person_has_fscores: bool = has_frigate_scores(name)
begin_batch(UPLOAD_TRACKER_FILE)
try:
for fname in person_files:
fpath = os.path.join(person_dir, fname)
@@ -598,6 +599,7 @@ def upload_to_frigate(jobs: list[dict]) -> None:
" was not filled this run — will be available next run"
)
finally:
flush_batch(UPLOAD_TRACKER_FILE)
# Batch-map Frigate filenames to asset IDs now that all uploads are done.
+3 -3
View File
@@ -69,10 +69,10 @@ def _resolve_strategy(strategy: str, has_embedding: bool) -> tuple[int | str, st
return _getenv_int("LIMIT", 30), "time"
custom_limit = _getenv_optional_int("LIMIT")
if custom_limit is not None:
if custom_limit == 0:
logger.warning("LIMIT=0 selects zero images — set LIMIT to a positive integer or leave unset for auto")
if custom_limit is not None and custom_limit > 0:
return custom_limit, "smart"
if custom_limit == 0:
logger.warning("LIMIT=0 is invalid — ignoring and using auto strategy")
strategy_map = {
"adaptive": ("auto", "smart"),
+6 -4
View File
@@ -116,9 +116,9 @@ def flush_batch(filename: str) -> None:
"""Write the accumulated cache state for filename to disk."""
path = _tracker_path(filename)
key = str(path)
_deferred.discard(key)
if key in _cache:
_write_to_disk(path, _cache[key])
_deferred.discard(key)
def _flat_key(filename: str) -> str:
@@ -239,9 +239,8 @@ def remove_frigate_file(person_name: str, frigate_filename: str) -> None:
def remove_frigate_files_batch(person_name: str, frigate_filenames: list[str]) -> None:
"""Remove multiple Frigate filenames in a single load/save."""
data = _load(UPLOAD_TRACKER_FILE)
by_person = data.get("by_person", {})
raw = by_person.get(person_name)
src = _load(UPLOAD_TRACKER_FILE)
raw = src.get("by_person", {}).get(person_name)
if raw is None:
return
entry = _migrate_entry(raw)
@@ -249,7 +248,10 @@ def remove_frigate_files_batch(person_name: str, frigate_filenames: list[str]) -
asset_id = entry["frigate_files"].pop(fn, None)
if asset_id is not None and asset_id not in entry["frigate_files"].values():
entry["frigate_scores"].pop(asset_id, None)
by_person = dict(src.get("by_person", {})) # copy so assignment does not mutate the cache
by_person[person_name] = entry
data = dict(src)
data["by_person"] = by_person
_save(UPLOAD_TRACKER_FILE, data)
logger.debug(f"Removed {len(frigate_filenames)} Frigate file mapping(s) for {person_name}")