Optimize historical match detail payload
This commit is contained in:
@@ -253,21 +253,9 @@ def _build_materialized_recent_item(item: dict[str, object]) -> dict[str, object
|
||||
|
||||
|
||||
def _build_materialized_detail_item(materialized: dict[str, object]) -> dict[str, object]:
|
||||
from .rcon_admin_log_storage import get_latest_rcon_player_profile_summaries
|
||||
|
||||
match = materialized["match"]
|
||||
recent_item = _build_materialized_recent_item(match)
|
||||
profile_summaries = get_latest_rcon_player_profile_summaries(
|
||||
target_key=str(match["target_key"]),
|
||||
player_ids=[str(row["player_id"]) for row in materialized["players"] if row.get("player_id")],
|
||||
)
|
||||
players = [
|
||||
_build_player_row(
|
||||
row,
|
||||
profile_summary=profile_summaries.get(str(row.get("player_id"))),
|
||||
)
|
||||
for row in materialized["players"]
|
||||
]
|
||||
players = [_build_player_row(row) for row in materialized["players"]]
|
||||
player_count = len(players) if players else recent_item.get("player_count")
|
||||
return {
|
||||
**recent_item,
|
||||
@@ -298,12 +286,10 @@ def _resolve_materialized_player_count(item: dict[str, object]) -> int | None:
|
||||
|
||||
def _build_player_row(
|
||||
row: dict[str, object],
|
||||
*,
|
||||
profile_summary: dict[str, object] | None = None,
|
||||
) -> dict[str, object]:
|
||||
kills = _coerce_optional_int(row.get("kills")) or 0
|
||||
deaths = _coerce_optional_int(row.get("deaths")) or 0
|
||||
player = {
|
||||
return {
|
||||
"player_name": row.get("player_name"),
|
||||
"team": row.get("team"),
|
||||
"kills": kills,
|
||||
@@ -315,9 +301,6 @@ def _build_player_row(
|
||||
"death_by": _top_counter(row.get("death_by_json")),
|
||||
**build_external_player_profile_fields(player_id=row.get("player_id")),
|
||||
}
|
||||
if profile_summary:
|
||||
player["profile_summary"] = profile_summary
|
||||
return player
|
||||
|
||||
|
||||
def _top_counter(raw_value: object, *, limit: int = 5) -> list[dict[str, object]]:
|
||||
|
||||
@@ -85,7 +85,7 @@ class RconMaterializationPipelineTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(players["Charlie"]["platform"], "unknown")
|
||||
self.assertNotIn("steam_id_64", players["Charlie"])
|
||||
self.assertNotIn("external_profile_links", players["Charlie"])
|
||||
self.assertEqual(players["Charlie"]["external_profile_links"], {})
|
||||
gc.collect()
|
||||
|
||||
def test_match_detail_marks_equal_materialized_timestamps_as_server_time_only(self) -> None:
|
||||
@@ -181,7 +181,7 @@ class RconMaterializationPipelineTests(unittest.TestCase):
|
||||
)
|
||||
gc.collect()
|
||||
|
||||
def test_match_detail_adds_safe_profile_summary_when_snapshot_exists(self) -> None:
|
||||
def test_match_detail_omits_profile_summary_when_snapshot_exists(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
db_path = Path(tmpdir) / "historical.sqlite3"
|
||||
previous_storage_path = os.environ.get("HLL_BACKEND_STORAGE_PATH")
|
||||
@@ -222,15 +222,11 @@ class RconMaterializationPipelineTests(unittest.TestCase):
|
||||
|
||||
self.assertIsNotNone(detail)
|
||||
players = {row["player_name"]: row for row in detail["players"]}
|
||||
self.assertIn("profile_summary", players["Alpha"])
|
||||
self.assertNotIn("profile_summary", players["Alpha"])
|
||||
self.assertNotIn("profile_summary", players["Bravo"])
|
||||
profile_summary = players["Alpha"]["profile_summary"]
|
||||
self.assertEqual(profile_summary["sessions"], 12)
|
||||
self.assertEqual(profile_summary["matches_played"], 9)
|
||||
self.assertEqual(profile_summary["totals"]["kills"], 141)
|
||||
self.assertEqual(profile_summary["favorite_weapons"], {"M1 Garand": 31})
|
||||
self.assertNotIn("raw_content", profile_summary)
|
||||
self.assertNotIn("player_id", players["Alpha"])
|
||||
self.assertEqual(players["Alpha"]["steam_id_64"], "76561198000000001")
|
||||
self.assertIn("external_profile_links", players["Alpha"])
|
||||
gc.collect()
|
||||
|
||||
def test_recent_matches_prefer_materialized_rcon_over_scoreboard_fallback(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user