perf: add patch_index flag to recalculate_elevation_hysteresis

Allows bulk callers to skip per-activity index.json rewrites and
batch the update themselves, reducing O(n²) index churn to O(n).
This commit is contained in:
Davide Scaini
2026-05-23 21:05:00 +02:00
parent 02edb0b0f9
commit 56932f7f25
+5 -2
View File
@@ -299,7 +299,9 @@ def recalculate_elevation(
}
def recalculate_elevation_hysteresis(user_dir: Path, activity_id: str) -> dict:
def recalculate_elevation_hysteresis(
user_dir: Path, activity_id: str, *, patch_index: bool = True
) -> dict:
"""Recompute elevation gain/loss from the original recorded elevation data.
Algorithm
@@ -370,7 +372,8 @@ def recalculate_elevation_hysteresis(user_dir: Path, activity_id: str) -> dict:
detail["elevation_loss_m"] = loss_r
json_path.write_text(json.dumps(detail, indent=2, ensure_ascii=False), encoding="utf-8")
# Patch index.json summary
# Patch index.json summary (skip for bulk callers who batch this themselves)
if patch_index:
index_path = user_dir / "index.json"
if index_path.exists():
index = json.loads(index_path.read_text(encoding="utf-8"))