Fix bugs in the filtering so hidden games are hidden, except in the hidden view, and update as soon as you hide them or unhide them.

This commit is contained in:
Daniel Johnson 2024-02-17 08:10:04 -05:00 committed by Mathieu Comandon
parent fefbb38d12
commit b840c1389f
2 changed files with 21 additions and 10 deletions

View file

@ -33,23 +33,30 @@ def get_category(name):
def get_game_ids_for_categories(included_category_names=None, excluded_category_names=None):
"""Get the ids of games in database."""
query = (
"SELECT games.id FROM games "
"LEFT OUTER JOIN games_categories ON games.id = games_categories.game_id "
"LEFT OUTER JOIN categories ON categories.id = games_categories.category_id"
)
filters = []
parameters = []
if included_category_names:
# Query that finds games in the included categories
query = (
"SELECT games.id FROM games "
"INNER JOIN games_categories ON games.id = games_categories.game_id "
"INNER JOIN categories ON categories.id = games_categories.category_id"
)
filters.append("categories.name IN (%s)" % ", ".join(repeat("?", len(included_category_names))))
parameters.extend(included_category_names)
else:
# Or, if you listed none, we fall back to all games
query = "SELECT games.id FROM games"
if excluded_category_names:
exclude_filter = "categories.name NOT IN (%s)" % ", ".join(repeat("?", len(excluded_category_names)))
if not included_category_names:
exclude_filter = f"({exclude_filter} OR categories.name IS NULL)"
# Sub-query to exclude the excluded categories, if any.
exclude_filter = (
"NOT EXISTS(SELECT * FROM games_categories AS gc "
"INNER JOIN categories AS c ON gc.category_id = c.id "
"WHERE gc.game_id = games.id "
"AND c.name IN (%s))" % ", ".join(repeat("?", len(excluded_category_names)))
)
filters.append(exclude_filter)
parameters.extend(excluded_category_names)

View file

@ -1036,7 +1036,11 @@ class LutrisWindow(Gtk.ApplicationWindow,
# If the update took the row out of this view's category, we'll need
# to update the view to reflect that.
if row.type in ("category", "user_category"):
if row.id != "all" and row.id not in game.get_categories():
categories = game.get_categories()
if row.id != ".hidden" and ".hidden" in categories:
return False
if row.id != "all" and row.id not in categories:
return False
return True