Optimize dashboard overview loading

This commit is contained in:
2026-06-06 00:42:00 +02:00
parent a412998c96
commit b340489d96
14 changed files with 990 additions and 88 deletions

View File

@@ -226,6 +226,34 @@ class TestTasks:
assert "High prio" in titles
assert "Low prio" not in titles
async def test_list_pagination_and_counts(self, client):
await _create_domain(client)
topic = await _create_topic(client)
ws = await _create_workstream(client, topic["id"])
first = await _create_task(client, ws["id"], title="First")
second = await _create_task(client, ws["id"], title="Second")
third = await _create_task(client, ws["id"], title="Third")
await client.patch(f"/tasks/{second['id']}", json={"status": "progress"})
await client.patch(f"/tasks/{third['id']}", json={"status": "wait", "blocking_reason": "blocked"})
r = await client.get("/tasks/?limit=2")
assert r.status_code == 200
body = r.json()
assert len(body) == 2
assert body[0]["id"] == first["id"]
assert body[1]["id"] == second["id"]
r = await client.get("/tasks/?limit=1&offset=2")
assert r.status_code == 200
assert [task["id"] for task in r.json()] == [third["id"]]
r = await client.get(f"/tasks/counts?workstream_id={ws['id']}")
assert r.status_code == 200
counts = {(row["workstream_id"], row["status"]): row["count"] for row in r.json()}
assert counts[(ws["id"], "todo")] == 1
assert counts[(ws["id"], "progress")] == 1
assert counts[(ws["id"], "wait")] == 1
@pytest.mark.parametrize("initial_status", ["proposed", "ready", "backlog"])
async def test_task_start_activates_planning_workstream(self, client, initial_status):
await _create_domain(client)
@@ -358,6 +386,34 @@ class TestStateSummary:
assert summaries[blocked_ws["id"]]["blocked_reasons"][0]["id"] == "dependencies.all_complete"
assert body["totals"]["workstreams"]["blocked"] == 1
async def test_overview_returns_chart_ready_rows(self, client):
await _create_domain(client)
topic = await _create_topic(client)
repo = await _create_repo(client)
ws = await _create_workstream(client, topic["id"], repo_id=repo["id"])
first = await _create_task(client, ws["id"], title="Todo")
second = await _create_task(client, ws["id"], title="Done")
await client.patch(f"/tasks/{second['id']}", json={"status": "done", "suppress_token_event": True})
r = await client.get("/state/overview")
assert r.status_code == 200
assert r.headers["x-statehub-cache"] == "miss"
body = r.json()
rows = {row["id"]: row for row in body["workplan_rows"]}
assert ws["id"] in rows
assert rows[ws["id"]]["repo_label"] == "test-repo"
assert rows[ws["id"]]["domain"] == "testdomain"
assert rows[ws["id"]]["todo"] == 1
assert rows[ws["id"]]["done"] == 1
assert rows[ws["id"]]["total"] == 2
assert body["totals"]["tasks"]["total"] == 2
assert body["diagnostics"]["task_count_strategy"] == "grouped"
r = await client.get("/state/overview")
assert r.status_code == 200
assert r.headers["x-statehub-cache"] == "hit"
class TestFlowEndpoints:
async def test_list_flow_definitions(self, client):