mirror of
https://github.com/lutris/lutris
synced 2024-10-14 11:42:36 +00:00
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.
This commit is contained in:
parent
06b0b2fbf7
commit
3d47983783
|
@ -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 = (
|
||||
|
|
Loading…
Reference in a new issue