perf(sim): preload all clips into memory for instant altitude swaps
Each altitude change reset the single <video> element's src and re-fetched the scale's footage over the network, compounded by the dev no-store policy applying to /media too — so every scale change paid a full fetch+decode. - simulator/app.py: split the cache middleware — app shell/JS/CSS stay no-store (by-eye dev iteration), but /media is now cacheable (public, max-age, immutable) since the clips are static. - simulator/static/app.js: preload every ring clip (19 base + 5 transition, ~350 MB) into in-memory blob object URLs at startup — non-blocking, the first scale plays immediately while the rest stream in, ordered current scale outward. mediaUrl() serves the cached blob when ready, else falls back to the network. A small progress chip self-removes when done. - tests: assert app assets stay no-store and /media is cacheable. 269 passed, 2 skipped. Frontend verified by-eye by the operator (no headless browser in repo yet). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,32 @@ def test_index_is_served():
|
||||
assert "Alteration" in resp.text
|
||||
|
||||
|
||||
def test_app_assets_are_not_cached(client):
|
||||
# Dev iteration relies on the browser never serving stale renderer code.
|
||||
resp = client.get("/")
|
||||
assert "no-store" in resp.headers.get("cache-control", "")
|
||||
|
||||
|
||||
def test_media_is_cacheable(tmp_path, monkeypatch):
|
||||
# Media is static: it must be browser-cacheable so the preloader's fetch (and
|
||||
# any fallback) doesn't re-hit the network on every altitude change.
|
||||
import simulator.app as appmod
|
||||
|
||||
media = tmp_path / "media"
|
||||
(media / "cosmos").mkdir(parents=True)
|
||||
(media / "cosmos" / "base.mp4").write_bytes(b"\x00\x00\x00\x18ftyp")
|
||||
monkeypatch.setattr(appmod, "MEDIA_DIR", media)
|
||||
manifest = tmp_path / "manifest.json"
|
||||
manifest.write_text(json.dumps({"clips": []}))
|
||||
|
||||
client = TestClient(create_app(manifest_path=manifest))
|
||||
resp = client.get("/media/cosmos/base.mp4")
|
||||
assert resp.status_code == 200
|
||||
cc = resp.headers.get("cache-control", "")
|
||||
assert "no-store" not in cc
|
||||
assert "max-age" in cc
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ring_manifest_path(tmp_path):
|
||||
p = tmp_path / "manifest.json"
|
||||
|
||||
Reference in New Issue
Block a user