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 <noreply@anthropic.com>
This commit is contained in:
Spinnich
2026-08-04 11:01:22 +00:00
parent e85f2fe4ef
commit d095f87feb
2 changed files with 2 additions and 15 deletions

View File

@@ -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": [],

View File

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