perf: reuse unchanged live snapshot values (Closes #519)
CI / lint (pull_request) Successful in 1m6s
CI / build-release (pull_request) Successful in 5s
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy committed 2026-08-10 22:54:08 +00:00
1 parent 5bef6291e8
commit fdcd0d31ab
4 files changed
+136 -2

No files matched your search

+42
View File
@@ -137,6 +137,48 @@ async def test_live_snapshot_omits_section_bodies_at_known_revisions(monkeypatch
assert "freshness" in second
@pytest.mark.anyio
async def test_warm_unchanged_polls_only_load_shared_metadata(monkeypatch):
async def user():
return {"id": 1, "login": "timmy"}
async def empty():
return []
monkeypatch.setattr(main, "current_user", user)
monkeypatch.setattr(main, "repos", empty)
monkeypatch.setattr(main, "issues", empty)
monkeypatch.setattr(main, "pull_requests", empty)
monkeypatch.setattr(main, "activity_events", lambda _user: empty())
monkeypatch.setattr(main, "notifications", empty)
first = payload(await main.live_snapshot())
full_load = main._live_snapshot_store.load
metadata_load = main._live_snapshot_store.load_metadata
calls = {"full": 0, "metadata": 0}
def counted_full_load():
calls["full"] += 1
return full_load()
def counted_metadata_load():
calls["metadata"] += 1
return metadata_load()
monkeypatch.setattr(main._live_snapshot_store, "load", counted_full_load)
monkeypatch.setattr(main._live_snapshot_store, "load_metadata", counted_metadata_load)
for _ in range(10):
response = await main.live_snapshot(
context_revision=first["revisions"]["context"],
events_revision=first["revisions"]["events"],
notifications_revision=first["revisions"]["notifications"],
)
assert response.status_code == 200
assert "context" not in payload(response)
assert calls == {"full": 0, "metadata": 10}
@pytest.mark.anyio
async def test_live_snapshot_token_from_another_worker_never_suppresses_content(monkeypatch, tmp_path):
async def user():
+21
View File
@@ -1,5 +1,6 @@
import threading
import os
import sqlite3
import pytest
@@ -7,6 +8,26 @@ from src import live_snapshot_store
from src.live_snapshot_store import LiveSnapshotStore, RefreshLeaseLost
def test_metadata_load_does_not_retrieve_or_decode_snapshot_value(tmp_path):
store = LiveSnapshotStore(tmp_path / "live.sqlite3", clock=lambda: 100.0)
with sqlite3.connect(store.path) as connection:
connection.execute(
"UPDATE live_snapshot SET value_json = ? WHERE singleton = 1",
("not-json",),
)
metadata = store.load_metadata()
assert metadata.created_at == {
section: None for section in ("context", "events", "notifications")
}
assert metadata.revisions == {
section: 0 for section in ("context", "events", "notifications")
}
with pytest.raises(ValueError):
store.load()
def test_independent_stores_racing_for_refresh_have_one_lease_winner(tmp_path):
path = tmp_path / "live.sqlite3"
first = LiveSnapshotStore(path, clock=lambda: 100.0)