cleanup backend

This commit is contained in:
Georges-Antoine Assi
2026-07-20 08:39:34 -04:00
parent a67132a908
commit 0332fa085b
3 changed files with 8 additions and 29 deletions

View File

@@ -100,12 +100,7 @@ def get_supported_platforms_endpoint(request: Request) -> list[PlatformSchema]:
@protected_route(router.get, "/filesystem", [Scope.PLATFORMS_READ])
async def get_filesystem_platforms_endpoint(request: Request) -> list[PlatformSchema]:
"""Retrieve platform folders on disk that have no database row yet.
These folders (created for a platform but not scanned yet) are invisible
to the scan picker because they have no ROMs imported, so they carry no
database row. Returning them lets the UI offer a first scan for them.
"""
"""Retrieve platform folders on disk that have no database row yet."""
return await get_filesystem_platforms()

View File

@@ -709,8 +709,7 @@ async def scan_platforms(
metadata_sources (list[str]): List of metadata sources to be used
scan_type (ScanType): Type of scan to be performed.
roms_ids (list[int], optional): List of selected roms to be scanned.
platform_fs_slugs (list[str], optional): Filesystem slugs of folders to
scan that have no database row yet (never-scanned platforms).
platform_fs_slugs (list[str], optional): Folders to scan with no database row.
"""
if not roms_ids:
roms_ids = []
@@ -744,12 +743,7 @@ async def scan_platforms(
db_platforms = db_platform_handler.get_platforms()
db_platforms_by_slug = {p.fs_slug: p for p in db_platforms}
# Selected platforms arrive as database ids (existing platforms) and/or
# filesystem slugs (a folder can be an existing platform or one on disk
# without a database row yet). Both resolve to a folder slug the scanner
# walks. Known database platforms are always accepted; a bare slug is only
# accepted when it maps to a folder on disk. When nothing is selected,
# every filesystem platform is scanned.
# Selected platforms arrive as database ids and/or filesystem slugs.
selected_slugs = [p.fs_slug for p in db_platforms if p.id in platform_ids]
for fs_slug in platform_fs_slugs:
if fs_slug in selected_slugs:
@@ -757,7 +751,8 @@ async def scan_platforms(
if fs_slug in db_platforms_by_slug or fs_slug in fs_platforms:
selected_slugs.append(fs_slug)
platform_list = sorted(selected_slugs or fs_platforms)
has_selection = bool(platform_ids or platform_fs_slugs)
platform_list = sorted(selected_slugs if has_selection else fs_platforms)
# A "new platforms" scan skips platforms that already exist in the database,
# so they must be excluded from the totals to keep the tracker accurate. This

View File

@@ -20,12 +20,7 @@ from models.platform import Platform
def _build_unmatched_platform(slug: str, fs_slug: str, now: datetime) -> PlatformSchema:
"""Build a PlatformSchema for a platform that has no database row yet.
Metadata is resolved from the local provider catalogs only (no network
calls). The entry carries id -1 and rom_count 0, matching the shape used
for unmatched supported platforms.
"""
"""Build a PlatformSchema for a platform that has no database row yet."""
igdb_platform = meta_igdb_handler.get_platform(slug)
moby_platform = meta_moby_handler.get_platform(slug)
ss_platform = meta_ss_handler.get_platform(slug)
@@ -124,14 +119,7 @@ def get_supported_platforms() -> list[PlatformSchema]:
async def get_filesystem_platforms() -> list[PlatformSchema]:
"""Get platform folders that exist on disk but have no database row yet.
A folder created for a platform (optionally bound in Library Management)
has no database row until its first scan imports a ROM, so it is invisible
to the scan platform picker. Surfacing these folders lets a first scan
target a brand-new platform. Slugs are resolved through the platform
binding/version config; metadata is resolved locally (no network calls).
"""
"""Get platform folders that exist on disk but have no database row yet."""
cnfg = cm.get_config()
fs_slugs = await fs_platform_handler.get_platforms()
existing_fs_slugs = {p.fs_slug for p in db_platform_handler.get_platforms()}
@@ -139,6 +127,7 @@ async def get_filesystem_platforms() -> list[PlatformSchema]:
now = datetime.now(timezone.utc)
filesystem_platforms = []
# Build a platform for each folder on disk
for fs_slug in fs_slugs:
if fs_slug in existing_fs_slugs:
continue