Fix segment effort duplicates; auto-scan on segment creation
- detect.py: truncate started_at to seconds so dedup key survives JSON round-trip - store.py: dedup by (activity_id, iso-started_at) string key, not object equality - server.py: extract _scan_segment_for_user helper; trigger background scan for the creating user's activities when a new segment is saved
This commit is contained in:
@@ -172,10 +172,10 @@ def save_efforts(data_dir: Path, handle: str, segment_id: str, efforts: list[Seg
|
||||
|
||||
|
||||
def add_effort(data_dir: Path, handle: str, segment_id: str, effort: SegmentEffort) -> None:
|
||||
"""Append an effort, replacing any existing effort for the same activity."""
|
||||
"""Append an effort, replacing any existing effort with the same activity + start time."""
|
||||
efforts = load_efforts(data_dir, handle, segment_id)
|
||||
efforts = [e for e in efforts if e.activity_id != effort.activity_id or
|
||||
e.started_at != effort.started_at]
|
||||
key = (effort.activity_id, _iso(effort.started_at))
|
||||
efforts = [e for e in efforts if (e.activity_id, _iso(e.started_at)) != key]
|
||||
efforts.append(effort)
|
||||
efforts.sort(key=lambda e: e.started_at, reverse=True)
|
||||
save_efforts(data_dir, handle, segment_id, efforts)
|
||||
|
||||
Reference in New Issue
Block a user