mirror of
https://github.com/rommapp/romm.git
synced 2026-06-27 22:35:57 +00:00
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:
@@ -11,7 +11,7 @@ class RegionBreakdownItem(TypedDict):
|
||||
count: int
|
||||
|
||||
|
||||
class StatsReturn(TypedDict):
|
||||
class StatsReturn(TypedDict, total=False):
|
||||
PLATFORMS: int
|
||||
ROMS: int
|
||||
SAVES: int
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user