From 3d47983783dc92d33671dc2baacf71b10833954a Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Fri, 12 Apr 2024 19:56:17 -0400 Subject: [PATCH] Rewrite uncategories game SQL with a subquery. This is so that it can exclude the 'favorite' category, so games added to favorites are not considered categories. Hidden games are still counted as categories, though they'd be hidden anyway. Also, Lutris game IDs are strings, not ints. --- lutris/database/categories.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lutris/database/categories.py b/lutris/database/categories.py index 2562bf272..9450dc982 100644 --- a/lutris/database/categories.py +++ b/lutris/database/categories.py @@ -16,7 +16,7 @@ class _SmartCategory(abc.ABC): pass @abc.abstractmethod - def get_games(self) -> List[int]: + def get_games(self) -> List[str]: pass @@ -26,14 +26,8 @@ class _SmartUncategorizedCategory(_SmartCategory): def get_name(self) -> str: return ".uncategorized" - def get_games(self) -> List[int]: - query = ( - "SELECT games.id FROM games " - "LEFT JOIN games_categories ON games.id = games_categories.game_id " - "WHERE games_categories.game_id IS NULL" - ) - uncategorized = sql.db_query(settings.DB_PATH, query) - return [row["id"] for row in uncategorized] + def get_games(self) -> List[str]: + return get_uncategorized_game_ids() # All smart categories should be added to this variable. @@ -118,6 +112,21 @@ def get_game_ids_for_categories(included_category_names=None, excluded_category_ return list(sorted(result)) +def get_uncategorized_game_ids() -> List[str]: + """Returns the ids of games that are in no categories. We do not count + the 'favorites' category, but we do count '.hidden'- hidden games are hidden + from this too.""" + query = ( + "SELECT games.id FROM games WHERE NOT EXISTS(" + "SELECT * FROM games_categories " + "INNER JOIN categories ON categories.id = games_categories.category_id " + "AND categories.name NOT IN ('all', 'favorite') " + "WHERE games.id = games_categories.game_id)" + ) + uncategorized = sql.db_query(settings.DB_PATH, query) + return [row["id"] for row in uncategorized] + + def get_categories_in_game(game_id): """Get the categories of a game in database.""" query = (