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 <noreply@anthropic.com>
This commit is contained in:
cc
2026-03-22 17:59:07 -04:00
parent c52bdf9b81
commit ce85a26185
3 changed files with 10 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ class RegionBreakdownItem(TypedDict):
count: int
class StatsReturn(TypedDict):
class StatsReturn(TypedDict, total=False):
PLATFORMS: int
ROMS: int
SAVES: int

View File

@@ -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

View File

@@ -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;
});
});