From d095f87febca43f0a3b8cae74716785de2cf6aca Mon Sep 17 00:00:00 2001 From: Spinnich Date: Tue, 4 Aug 2026 11:01:22 +0000 Subject: [PATCH] refactor(home): reuse get_roms_count for the setup-library bail-out Swap the purpose-built has_any_rom() probe for the existing db_stats_handler.get_roms_count(), per review. The count is already served from an index-only scan and backs the stats endpoint, so it carries the same cost here without adding a second way to ask the database whether the library has been scanned. Leaves roms_handler.py untouched by this branch. Co-Authored-By: Claude Opus 5 --- backend/endpoints/heartbeat.py | 4 ++-- backend/handler/database/roms_handler.py | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/backend/endpoints/heartbeat.py b/backend/endpoints/heartbeat.py index 76da89319..e67e80309 100644 --- a/backend/endpoints/heartbeat.py +++ b/backend/endpoints/heartbeat.py @@ -29,7 +29,7 @@ from decorators.auth import protected_route from endpoints.responses.heartbeat import HeartbeatResponse from exceptions.fs_exceptions import PlatformAlreadyExistsException from handler.auth.constants import Scope -from handler.database import db_rom_handler, db_user_handler +from handler.database import db_stats_handler, db_user_handler from handler.filesystem import fs_platform_handler from handler.filesystem.base_handler import LibraryStructure from handler.metadata import ( @@ -218,7 +218,7 @@ async def get_setup_library_info(request: Request): # instance can show what RomM already sees on disk. Once the database # holds ROMs that hint is dead weight, and building it walks every # platform directory: tens of seconds on a large library. - if db_rom_handler.has_any_rom(): + if db_stats_handler.get_roms_count() > 0: return { "detected_structure": detected_structure, "existing_platforms": [], diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 0c1495a5b..353cea176 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -1642,19 +1642,6 @@ class DBRomsHandler(DBBaseHandler): or 0 ) - @begin_session - def has_any_rom( - self, - *, - session: Session = None, # type: ignore - ) -> bool: - """Whether the library holds at least one ROM. - - An existence probe rather than a count, for callers that only - need to know whether the library has ever been scanned. - """ - return session.scalar(select(Rom.id).limit(1)) is not None - @begin_session def get_roms_by_fs_name( self,