From fb8f234ba47dea7a641009f1f2c89fca16c64d1c Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Thu, 19 Jun 2025 10:26:18 -0300 Subject: [PATCH 1/2] misc: Remove deprecated boolean parameters from get_roms endpoint These parameters were replaced by optional versions that allow for more flexibility. This change removes code already marked as deprecated. --- backend/endpoints/rom.py | 40 +----------------------- backend/handler/database/roms_handler.py | 11 ++++--- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index 143a0dd87..fc45f721e 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -5,7 +5,7 @@ from datetime import datetime, timezone from io import BytesIO from shutil import rmtree from stat import S_IFREG -from typing import Annotated, Any, TypeVar +from typing import Any, TypeVar from urllib.parse import quote from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile, ZipInfo @@ -160,15 +160,6 @@ def get_roms( missing: bool | None = None, has_ra: bool | None = None, verified: bool | None = None, - # TODO: Remove deprecated boolean parameters, in favor of their - # optional counterparts. - unmatched_only: Annotated[bool, Query(deprecated=True)] = False, - matched_only: Annotated[bool, Query(deprecated=True)] = False, - favourites_only: Annotated[bool, Query(deprecated=True)] = False, - duplicates_only: Annotated[bool, Query(deprecated=True)] = False, - playables_only: Annotated[bool, Query(deprecated=True)] = False, - missing_only: Annotated[bool, Query(deprecated=True)] = False, - ra_only: Annotated[bool, Query(deprecated=True)] = False, group_by_meta_id: bool = False, selected_genre: str | None = None, selected_franchise: str | None = None, @@ -195,13 +186,6 @@ def get_roms( playable (bool, optional): Filter for playable or non-playable roms. Defaults to None. missing (bool, optional): Filter only roms that are missing from the filesystem. Defaults to False. verified (bool, optional): Filter only roms that are verified by hasheous from the filesystem. Defaults to False. - unmatched_only (bool, optional): Filter only unmatched roms. Defaults to False. DEPRECATED: use `matched` instead. - matched_only (bool, optional): Filter only matched roms. Defaults to False. DEPRECATED: use `matched` instead. - favourites_only (bool, optional): Filter only favourite roms. Defaults to False. DEPRECATED: use `favourite` instead. - duplicates_only (bool, optional): Filter only duplicate roms. Defaults to False. DEPRECATED: use `duplicate` instead. - playables_only (bool, optional): Filter only playable roms by emulatorjs. Defaults to False. DEPRECATED: use `playable` instead. - ra_only (bool, optional): Filter only roms with Retroachievements compatibility. Defaults to False. DEPRECATED: use `has_ra` instead. - missing_only (bool, optional): Filter only roms that are missing from the filesystem. Defaults to False. DEPRECATED: use `missing` instead. group_by_meta_id (bool, optional): Group roms by igdb/moby/ssrf/launchbox ID. Defaults to False. selected_genre (str, optional): Filter by genre. Defaults to None. selected_franchise (str, optional): Filter by franchise. Defaults to None. @@ -223,28 +207,6 @@ def get_roms( order_dir=order_dir.lower(), ) - # Backwards compatibility for matched parameter. - if matched is None: - if unmatched_only: - matched = False - elif matched_only: - matched = True - # Backwards compatibility for favourite parameter. - if favourite is None and favourites_only: - favourite = True - # Backwards compatibility for duplicate parameter. - if duplicate is None and duplicates_only: - duplicate = True - # Backwards compatibility for playable parameter. - if playable is None and playables_only: - playable = True - # Backwards compatibility for has_ra parameter. - if has_ra is None and ra_only: - has_ra = True - # Backwards compatibility for missing parameter. - if missing is None and missing_only: - missing = True - # Filter down the query query = db_rom_handler.filter_roms( query=query, diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index f805ea398..bd5f38d3f 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -236,8 +236,11 @@ class DBRomsHandler(DBBaseHandler): predicate = not_(predicate) return query.join(Rom.platform).filter(predicate) - def filter_by_has_ra(self, query: Query): - return query.filter(Rom.ra_id.isnot(None)) + def filter_by_has_ra(self, query: Query, value: bool) -> Query: + predicate = query.filter(Rom.ra_id.isnot(None)) + if not value: + predicate = not_(predicate) + return query.filter(predicate) def filter_by_missing_from_fs(self, query: Query): return query.filter(Rom.missing_from_fs.isnot(False)) @@ -431,8 +434,8 @@ class DBRomsHandler(DBBaseHandler): if playable is not None: query = self.filter_by_playable(query, value=playable) - if has_ra: - query = self.filter_by_has_ra(query) + if has_ra is not None: + query = self.filter_by_has_ra(query, value=has_ra) if missing: query = self.filter_by_missing_from_fs(query) From 3f9957ab40036a6570d79c29d6741d1c271861a1 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Thu, 19 Jun 2025 14:20:12 -0300 Subject: [PATCH 2/2] fix: Query filters and boolean default values --- backend/handler/database/roms_handler.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index bd5f38d3f..2e5744018 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -237,13 +237,16 @@ class DBRomsHandler(DBBaseHandler): return query.join(Rom.platform).filter(predicate) def filter_by_has_ra(self, query: Query, value: bool) -> Query: - predicate = query.filter(Rom.ra_id.isnot(None)) + predicate = Rom.ra_id.isnot(None) if not value: predicate = not_(predicate) return query.filter(predicate) - def filter_by_missing_from_fs(self, query: Query): - return query.filter(Rom.missing_from_fs.isnot(False)) + def filter_by_missing_from_fs(self, query: Query, value: bool) -> Query: + predicate = Rom.missing_from_fs.isnot(False) + if not value: + predicate = not_(predicate) + return query.filter(predicate) def filter_by_verified(self, query: Query): keys_to_check = [ @@ -391,9 +394,9 @@ class DBRomsHandler(DBBaseHandler): favourite: bool | None = None, duplicate: bool | None = None, playable: bool | None = None, - has_ra: bool | None = False, - missing: bool | None = False, - verified: bool | None = False, + has_ra: bool | None = None, + missing: bool | None = None, + verified: bool | None = None, group_by_meta_id: bool = False, selected_genre: str | None = None, selected_franchise: str | None = None, @@ -437,9 +440,10 @@ class DBRomsHandler(DBBaseHandler): if has_ra is not None: query = self.filter_by_has_ra(query, value=has_ra) - if missing: - query = self.filter_by_missing_from_fs(query) + if missing is not None: + query = self.filter_by_missing_from_fs(query, value=missing) + # TODO: Correctly support true/false values. if verified: query = self.filter_by_verified(query) @@ -615,6 +619,9 @@ class DBRomsHandler(DBBaseHandler): favourite=kwargs.pop("favourite", None), duplicate=kwargs.pop("duplicate", None), playable=kwargs.pop("playable", None), + has_ra=kwargs.pop("has_ra", None), + missing=kwargs.pop("missing", None), + verified=kwargs.pop("verified", None), selected_genre=kwargs.pop("selected_genre", None), selected_franchise=kwargs.pop("selected_franchise", None), selected_collection=kwargs.pop("selected_collection", None),