From e24a3b86bd24728242e184888e29452b0f27f7ab Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 12 Aug 2024 11:37:49 -0400 Subject: [PATCH 1/2] Hotfix scans when running HASH_SCAN --- backend/alembic/versions/0025_roms_hashes.py | 2 +- backend/endpoints/sockets/scan.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/alembic/versions/0025_roms_hashes.py b/backend/alembic/versions/0025_roms_hashes.py index 7dd5f3659..58af18400 100644 --- a/backend/alembic/versions/0025_roms_hashes.py +++ b/backend/alembic/versions/0025_roms_hashes.py @@ -28,7 +28,7 @@ def upgrade() -> None: sa.Column("sha1_hash", sa.String(length=100), nullable=True) ) - # Run a no-scan in the background on startup + # Run a no-scan in the background on migrate if not IS_PYTEST_RUN: high_prio_queue.enqueue( scan_platforms, [], ScanType.HASH_SCAN, [], [], job_timeout=SCAN_TIMEOUT diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index 4dc9bb7b8..cf6d50b58 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -341,6 +341,10 @@ async def _identify_rom( _added_rom = db_rom_handler.add_rom(scanned_rom) + # Return early if we're only scanning for hashes + if scan_type == ScanType.HASH_SCAN: + return scan_stats + path_cover_s, path_cover_l = await fs_resource_handler.get_cover( overwrite=True, entity=_added_rom, From b3a50021b740ad613c5eb8de3cb2d21256d6bf8f Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 12 Aug 2024 11:57:47 -0400 Subject: [PATCH 2/2] run quick before hash scan --- backend/alembic/versions/0025_roms_hashes.py | 6 +++++- backend/endpoints/sockets/scan.py | 4 ++-- backend/handler/scan_handler.py | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/alembic/versions/0025_roms_hashes.py b/backend/alembic/versions/0025_roms_hashes.py index 58af18400..0d14ade97 100644 --- a/backend/alembic/versions/0025_roms_hashes.py +++ b/backend/alembic/versions/0025_roms_hashes.py @@ -31,7 +31,11 @@ def upgrade() -> None: # Run a no-scan in the background on migrate if not IS_PYTEST_RUN: high_prio_queue.enqueue( - scan_platforms, [], ScanType.HASH_SCAN, [], [], job_timeout=SCAN_TIMEOUT + scan_platforms, [], ScanType.QUICK, [], [], job_timeout=SCAN_TIMEOUT + ) + + high_prio_queue.enqueue( + scan_platforms, [], ScanType.HASHES, [], [], job_timeout=SCAN_TIMEOUT ) diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index cf6d50b58..f66103452 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -82,7 +82,7 @@ def _should_scan_rom(scan_type: ScanType, rom: Rom, roms_ids: list): return ( (scan_type in {ScanType.NEW_PLATFORMS, ScanType.QUICK} and not rom) or (scan_type == ScanType.COMPLETE) - or (scan_type == ScanType.HASH_SCAN) + or (scan_type == ScanType.HASHES) or ( rom and ( @@ -342,7 +342,7 @@ async def _identify_rom( _added_rom = db_rom_handler.add_rom(scanned_rom) # Return early if we're only scanning for hashes - if scan_type == ScanType.HASH_SCAN: + if scan_type == ScanType.HASHES: return scan_stats path_cover_s, path_cover_l = await fs_resource_handler.get_cover( diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index 9ef7d5e5b..13bc0937e 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -24,7 +24,7 @@ class ScanType(Enum): UNIDENTIFIED = "unidentified" PARTIAL = "partial" COMPLETE = "complete" - HASH_SCAN = "hash_scan" + HASHES = "hashes" async def _get_main_platform_igdb_id(platform: Platform): @@ -231,12 +231,12 @@ async def scan_rom( ) # Calculating hashes is expensive, so we only do it if necessary - if not rom or scan_type == ScanType.COMPLETE or scan_type == ScanType.HASH_SCAN: + if not rom or scan_type == ScanType.COMPLETE or scan_type == ScanType.HASHES: rom_hashes = fs_rom_handler.get_rom_hashes(rom_attrs["file_name"], roms_path) rom_attrs.update(**rom_hashes) # If no metadata scan is required - if scan_type == ScanType.HASH_SCAN: + if scan_type == ScanType.HASHES: return Rom(**rom_attrs) async def fetch_igdb_rom():