From ce85a26185f8f72a86383e3c6f0c20876caba331 Mon Sep 17 00:00:00 2001 From: cc Date: Sun, 22 Mar 2026 17:59:07 -0400 Subject: [PATCH] fix: skip expensive platform stats on homepage The /stats endpoint is called on both the homepage and the server stats page, but only the stats page displays metadata coverage and region breakdown. Add an `include_platform_stats` query param (default false) so the homepage avoids the expensive per-platform queries. Co-Authored-By: Claude Opus 4.6 --- backend/endpoints/responses/stats.py | 2 +- backend/endpoints/stats.py | 12 ++++++++---- frontend/src/views/Settings/ServerStats.vue | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/endpoints/responses/stats.py b/backend/endpoints/responses/stats.py index 5873526a6..495c6aa00 100644 --- a/backend/endpoints/responses/stats.py +++ b/backend/endpoints/responses/stats.py @@ -11,7 +11,7 @@ class RegionBreakdownItem(TypedDict): count: int -class StatsReturn(TypedDict): +class StatsReturn(TypedDict, total=False): PLATFORMS: int ROMS: int SAVES: int diff --git a/backend/endpoints/stats.py b/backend/endpoints/stats.py index 1d77766b4..3072d287a 100644 --- a/backend/endpoints/stats.py +++ b/backend/endpoints/stats.py @@ -9,20 +9,24 @@ router = APIRouter( @router.get("") -def stats() -> StatsReturn: +def stats(include_platform_stats: bool = False) -> StatsReturn: """Endpoint to return the current RomM stats Returns: dict: Dictionary with all the stats """ - return { + result: StatsReturn = { "PLATFORMS": db_stats_handler.get_platforms_count(), "ROMS": db_stats_handler.get_roms_count(), "SAVES": db_stats_handler.get_saves_count(), "STATES": db_stats_handler.get_states_count(), "SCREENSHOTS": db_stats_handler.get_screenshots_count(), "TOTAL_FILESIZE_BYTES": db_stats_handler.get_total_filesize(), - "METADATA_COVERAGE": db_stats_handler.get_metadata_coverage_by_platform(), - "REGION_BREAKDOWN": db_stats_handler.get_region_breakdown_by_platform(), } + + if include_platform_stats: + result["METADATA_COVERAGE"] = db_stats_handler.get_metadata_coverage_by_platform() + result["REGION_BREAKDOWN"] = db_stats_handler.get_region_breakdown_by_platform() + + return result diff --git a/frontend/src/views/Settings/ServerStats.vue b/frontend/src/views/Settings/ServerStats.vue index edee85f26..79a16b9ef 100644 --- a/frontend/src/views/Settings/ServerStats.vue +++ b/frontend/src/views/Settings/ServerStats.vue @@ -18,7 +18,7 @@ const stats = ref({ }); onBeforeMount(() => { - api.get("/stats").then(({ data }) => { + api.get("/stats", { params: { include_platform_stats: true } }).then(({ data }) => { stats.value = data; }); });