fix: prune dist/data before rsync in _trigger_rebuild and manual rebuild endpoint

Same fix as cea1dbc (post-receive hook) but missed in server.py: Astro resolves
the public/data symlink and copies all activity JSON into dist/; without pruning,
every Strava sync / upload / edit that triggers a full build + rsync duplicates
GBs of data into the nginx webroot.

Both rsync callsites now rm -rf dist/data + pass --exclude=data/ to rsync.
This commit is contained in:
Davide Scaini
2026-04-22 11:01:01 +02:00
parent df496a017f
commit 6dc1fb6f20
+13 -2
View File
@@ -375,8 +375,15 @@ def _trigger_rebuild(handle: str) -> None:
_handle, result.returncode, result.stdout, result.stderr) _handle, result.returncode, result.stdout, result.stderr)
else: else:
log.info("rebuild[%s]: build done, rsyncing", _handle) log.info("rebuild[%s]: build done, rsyncing", _handle)
# Prune dist/data/ before rsync: Astro resolves the
# public/data symlink and copies all activity JSON into
# dist/, but nginx already serves /data/ directly from
# the live data dir — rsyncing it would duplicate GBs.
dist_data = Path(_site_dir) / "dist" / "data"
if dist_data.exists():
shutil.rmtree(dist_data)
rsync = subprocess.run( rsync = subprocess.run(
["rsync", "-a", "--delete", ["rsync", "-a", "--delete", "--exclude=data/",
f"{_site_dir}/dist/", _webroot + "/"], f"{_site_dir}/dist/", _webroot + "/"],
capture_output=True, capture_output=True,
text=True, text=True,
@@ -707,8 +714,12 @@ async def admin_rebuild_sync(
} }
if result.returncode == 0 and webroot: if result.returncode == 0 and webroot:
dist_data = site_dir / "dist" / "data"
if dist_data.exists():
shutil.rmtree(dist_data)
rsync = subprocess.run( rsync = subprocess.run(
["rsync", "-a", "--delete", f"{site_dir}/dist/", str(webroot) + "/"], ["rsync", "-a", "--delete", "--exclude=data/",
f"{site_dir}/dist/", str(webroot) + "/"],
capture_output=True, text=True, timeout=120, capture_output=True, text=True, timeout=120,
) )
resp["rsync_returncode"] = rsync.returncode resp["rsync_returncode"] = rsync.returncode