mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 01:58:41 +01:00
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:
@@ -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": [],
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user