fix(feed): update feed.json after every upload so browser sees new activities

merge_all(user_dir) updates the per-user _merged/ shard but the home page
loads feed.json first via loadCombinedFeed. write_combined_feed was only
called by the CLI render command, not by the API upload endpoints or the
dev watcher, leaving feed.json permanently stale after any runtime upload.

Add write_combined_feed(_get_data_dir()) after every merge_all call in
/api/upload/bas, /api/upload/raw, the dev.py file watcher, and dev startup.
This commit is contained in:
Davide Scaini
2026-04-26 21:37:19 +02:00
parent 1c9b89cd1c
commit b1cf18a2f0
2 changed files with 8 additions and 3 deletions
+4 -1
View File
@@ -66,8 +66,10 @@ def _user_dirs(data: Path) -> list[Path]:
def _merge_all_users(data: Path) -> None: def _merge_all_users(data: Path) -> None:
from bincio.render.cli import _merge_edits, _write_root_manifest from bincio.render.cli import _merge_edits, _write_root_manifest
from bincio.render.merge import write_combined_feed
_merge_edits(data) _merge_edits(data)
_write_root_manifest(data) _write_root_manifest(data)
write_combined_feed(data)
def _local_ip() -> str: def _local_ip() -> str:
@@ -148,8 +150,9 @@ def _watch_data(data: Path) -> None:
for user_dir in affected: for user_dir in affected:
handle = user_dir.name handle = user_dir.name
try: try:
from bincio.render.merge import merge_all from bincio.render.merge import merge_all, write_combined_feed
merge_all(user_dir) merge_all(user_dir)
write_combined_feed(data)
console.print(f" [dim]↺ {handle}: merged[/dim]") console.print(f" [dim]↺ {handle}: merged[/dim]")
except Exception as exc: except Exception as exc:
console.print(f" [yellow]⚠ {handle}: merge failed — {exc}[/yellow]") console.print(f" [yellow]⚠ {handle}: merge failed — {exc}[/yellow]")
+4 -2
View File
@@ -532,8 +532,9 @@ async def upload_bas_activity(
if not gj_path.exists(): if not gj_path.exists():
gj_path.write_text(json.dumps(body["geojson"], ensure_ascii=False), encoding="utf-8") gj_path.write_text(json.dumps(body["geojson"], ensure_ascii=False), encoding="utf-8")
from bincio.render.merge import merge_all from bincio.render.merge import merge_all, write_combined_feed
merge_all(user_dir) merge_all(user_dir)
write_combined_feed(_get_data_dir())
log.info("upload/bas[%s]: imported %s", user.handle, activity_id) log.info("upload/bas[%s]: imported %s", user.handle, activity_id)
return JSONResponse({"ok": True, "id": activity_id, "status": "imported"}) return JSONResponse({"ok": True, "id": activity_id, "status": "imported"})
@@ -621,8 +622,9 @@ async def upload_raw_activity(
if geojson and not (acts_dir / f"{act_id}.geojson").exists(): if geojson and not (acts_dir / f"{act_id}.geojson").exists():
(acts_dir / f"{act_id}.geojson").write_text(json.dumps(geojson), encoding="utf-8") (acts_dir / f"{act_id}.geojson").write_text(json.dumps(geojson), encoding="utf-8")
from bincio.render.merge import merge_all from bincio.render.merge import merge_all, write_combined_feed
merge_all(user_dir) merge_all(user_dir)
write_combined_feed(_get_data_dir())
except Exception as exc: except Exception as exc:
log.warning("upload/raw[%s]: extraction failed: %s", user.handle, exc) log.warning("upload/raw[%s]: extraction failed: %s", user.handle, exc)