Fix legacy historical recent matches fast path

This commit is contained in:
devRaGonSa
2026-06-10 20:49:54 +02:00
parent 0317894bed
commit 9809161aa6
5 changed files with 265 additions and 18 deletions

View File

@@ -1075,23 +1075,11 @@ def build_recent_historical_matches_payload(
server_slug: str | None = None,
) -> dict[str, object]:
"""Return recent historical matches from persisted CRCON data."""
if server_slug == ALL_SERVERS_SLUG:
snapshot_payload = build_recent_historical_matches_snapshot_payload(
if server_slug:
return _build_recent_historical_matches_legacy_snapshot_payload(
limit=limit,
server_slug=server_slug,
)
data = dict(snapshot_payload.get("data") or {})
data.update(
{
"title": "Partidas recientes por servidor",
"context": "historical-recent-matches",
"source": "historical-precomputed-snapshots",
"historical_data_source": get_historical_data_source_kind(),
"coverage_basis": "precomputed-recent-matches-snapshot",
"legacy_endpoint_policy": "snapshot-read-only-fast-path",
}
)
return {"status": snapshot_payload.get("status", "ok"), "data": data}
if get_historical_data_source_kind() == "rcon":
data_source = get_rcon_historical_read_model()
@@ -1215,6 +1203,29 @@ def build_recent_historical_matches_payload(
}
def _build_recent_historical_matches_legacy_snapshot_payload(
*,
limit: int,
server_slug: str,
) -> dict[str, object]:
snapshot_payload = build_recent_historical_matches_snapshot_payload(
limit=limit,
server_slug=server_slug,
)
data = dict(snapshot_payload.get("data") or {})
data.update(
{
"title": "Partidas recientes por servidor",
"context": "historical-recent-matches",
"source": "historical-precomputed-snapshots",
"historical_data_source": get_historical_data_source_kind(),
"coverage_basis": "precomputed-recent-matches-snapshot",
"legacy_endpoint_policy": "snapshot-read-only-fast-path",
}
)
return {"status": snapshot_payload.get("status", "ok"), "data": data}
def build_historical_match_detail_payload(
*,
server_slug: str,

View File

@@ -168,7 +168,7 @@ class HistoricalSnapshotRefreshTests(unittest.TestCase):
self.assertEqual(len(payload["data"]["items"]), 1)
self.assertFalse(payload["data"].get("fallback_used", False))
def test_legacy_all_servers_recent_matches_uses_snapshot_fast_path(self) -> None:
def test_legacy_recent_matches_uses_snapshot_fast_path(self) -> None:
snapshot = {
"generated_at": "2026-06-10T04:00:00Z",
"source_range_start": "2026-06-09T21:00:00Z",
@@ -191,7 +191,7 @@ class HistoricalSnapshotRefreshTests(unittest.TestCase):
patch("app.payloads.list_recent_historical_matches") as fallback_loader,
):
payload = build_recent_historical_matches_payload(
server_slug="all-servers",
server_slug="comunidad-hispana-01",
limit=20,
)
@@ -199,8 +199,73 @@ class HistoricalSnapshotRefreshTests(unittest.TestCase):
fallback_loader.assert_not_called()
self.assertEqual(payload["data"]["context"], "historical-recent-matches")
self.assertEqual(payload["data"]["legacy_endpoint_policy"], "snapshot-read-only-fast-path")
self.assertEqual(payload["data"]["server_slug"], "comunidad-hispana-01")
self.assertEqual(payload["data"]["items"][0]["match_id"], "match-1")
def test_legacy_second_server_recent_matches_uses_snapshot_fast_path(self) -> None:
snapshot = {
"generated_at": "2026-06-10T04:00:00Z",
"source_range_start": "2026-06-09T21:00:00Z",
"source_range_end": "2026-06-09T22:00:00Z",
"is_stale": False,
"payload": {
"items": [
{
"match_id": "match-2",
"closed_at": "2026-06-09T22:00:00Z",
}
],
"limit": 100,
},
}
with (
patch("app.payloads._get_historical_snapshot_record", return_value=snapshot),
patch("app.payloads.get_historical_data_source_kind", return_value="rcon"),
patch("app.payloads.get_rcon_historical_read_model") as rcon_loader,
patch("app.payloads.list_recent_historical_matches") as fallback_loader,
):
payload = build_recent_historical_matches_payload(
server_slug="comunidad-hispana-02",
limit=20,
)
rcon_loader.assert_not_called()
fallback_loader.assert_not_called()
self.assertEqual(payload["data"]["server_slug"], "comunidad-hispana-02")
self.assertEqual(payload["data"]["items"][0]["match_id"], "match-2")
def test_legacy_all_servers_recent_matches_still_uses_snapshot_fast_path(self) -> None:
snapshot = {
"generated_at": "2026-06-10T04:00:00Z",
"source_range_start": "2026-06-09T21:00:00Z",
"source_range_end": "2026-06-09T22:00:00Z",
"is_stale": False,
"payload": {
"items": [
{
"match_id": "match-all",
"closed_at": "2026-06-09T22:00:00Z",
}
],
"limit": 100,
},
}
with (
patch("app.payloads._get_historical_snapshot_record", return_value=snapshot),
patch("app.payloads.get_historical_data_source_kind", return_value="rcon"),
patch("app.payloads.get_rcon_historical_read_model") as rcon_loader,
patch("app.payloads.list_recent_historical_matches") as fallback_loader,
):
payload = build_recent_historical_matches_payload(
server_slug="all-servers",
limit=20,
)
rcon_loader.assert_not_called()
fallback_loader.assert_not_called()
self.assertEqual(payload["data"]["server_slug"], "all-servers")
self.assertEqual(payload["data"]["items"][0]["match_id"], "match-all")
def test_legacy_server_summary_uses_snapshot_fast_path(self) -> None:
snapshot = {
"generated_at": "2026-06-10T04:00:00Z",