fix: address 4 quality review findings — flush_batch order, batch finally guard, cache copy, LIMIT=0 fallthrough
This commit is contained in:
@@ -368,6 +368,7 @@ def upload_to_frigate(jobs: list[dict]) -> None:
|
|||||||
person_has_fscores: bool = has_frigate_scores(name)
|
person_has_fscores: bool = has_frigate_scores(name)
|
||||||
|
|
||||||
begin_batch(UPLOAD_TRACKER_FILE)
|
begin_batch(UPLOAD_TRACKER_FILE)
|
||||||
|
try:
|
||||||
for fname in person_files:
|
for fname in person_files:
|
||||||
fpath = os.path.join(person_dir, fname)
|
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"
|
" was not filled this run — will be available next run"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
finally:
|
||||||
flush_batch(UPLOAD_TRACKER_FILE)
|
flush_batch(UPLOAD_TRACKER_FILE)
|
||||||
|
|
||||||
# Batch-map Frigate filenames to asset IDs now that all uploads are done.
|
# Batch-map Frigate filenames to asset IDs now that all uploads are done.
|
||||||
|
|||||||
+3
-3
@@ -69,10 +69,10 @@ def _resolve_strategy(strategy: str, has_embedding: bool) -> tuple[int | str, st
|
|||||||
return _getenv_int("LIMIT", 30), "time"
|
return _getenv_int("LIMIT", 30), "time"
|
||||||
|
|
||||||
custom_limit = _getenv_optional_int("LIMIT")
|
custom_limit = _getenv_optional_int("LIMIT")
|
||||||
if custom_limit is not None:
|
if custom_limit is not None and custom_limit > 0:
|
||||||
if custom_limit == 0:
|
|
||||||
logger.warning("LIMIT=0 selects zero images — set LIMIT to a positive integer or leave unset for auto")
|
|
||||||
return custom_limit, "smart"
|
return custom_limit, "smart"
|
||||||
|
if custom_limit == 0:
|
||||||
|
logger.warning("LIMIT=0 is invalid — ignoring and using auto strategy")
|
||||||
|
|
||||||
strategy_map = {
|
strategy_map = {
|
||||||
"adaptive": ("auto", "smart"),
|
"adaptive": ("auto", "smart"),
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ def flush_batch(filename: str) -> None:
|
|||||||
"""Write the accumulated cache state for filename to disk."""
|
"""Write the accumulated cache state for filename to disk."""
|
||||||
path = _tracker_path(filename)
|
path = _tracker_path(filename)
|
||||||
key = str(path)
|
key = str(path)
|
||||||
_deferred.discard(key)
|
|
||||||
if key in _cache:
|
if key in _cache:
|
||||||
_write_to_disk(path, _cache[key])
|
_write_to_disk(path, _cache[key])
|
||||||
|
_deferred.discard(key)
|
||||||
|
|
||||||
|
|
||||||
def _flat_key(filename: str) -> str:
|
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:
|
def remove_frigate_files_batch(person_name: str, frigate_filenames: list[str]) -> None:
|
||||||
"""Remove multiple Frigate filenames in a single load/save."""
|
"""Remove multiple Frigate filenames in a single load/save."""
|
||||||
data = _load(UPLOAD_TRACKER_FILE)
|
src = _load(UPLOAD_TRACKER_FILE)
|
||||||
by_person = data.get("by_person", {})
|
raw = src.get("by_person", {}).get(person_name)
|
||||||
raw = by_person.get(person_name)
|
|
||||||
if raw is None:
|
if raw is None:
|
||||||
return
|
return
|
||||||
entry = _migrate_entry(raw)
|
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)
|
asset_id = entry["frigate_files"].pop(fn, None)
|
||||||
if asset_id is not None and asset_id not in entry["frigate_files"].values():
|
if asset_id is not None and asset_id not in entry["frigate_files"].values():
|
||||||
entry["frigate_scores"].pop(asset_id, None)
|
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
|
by_person[person_name] = entry
|
||||||
|
data = dict(src)
|
||||||
|
data["by_person"] = by_person
|
||||||
_save(UPLOAD_TRACKER_FILE, data)
|
_save(UPLOAD_TRACKER_FILE, data)
|
||||||
logger.debug(f"Removed {len(frigate_filenames)} Frigate file mapping(s) for {person_name}")
|
logger.debug(f"Removed {len(frigate_filenames)} Frigate file mapping(s) for {person_name}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user