mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
fix(steam): show imported games in collections that ignore Steam
A sync refreshed only the importing user's smart collections filtering on owned_on_steam, and left every other collection to the metadata scan it queues. A collection holding all Windows games therefore kept its old count and covers until that scan ran, and never updated at all when no scan worker was running. Store-only roms are library rows like any other, so the sync now refreshes the collections they match as soon as they are committed. `add_store_only_roms` reports the ids it inserted instead of how many, which the sync result still counts. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NH5s4gb7QNE7xa4pRUsBzx
This commit is contained in:
@@ -44,7 +44,7 @@ def _still_linked(session: Session, user_id: int, steam_id: str) -> bool:
|
|||||||
|
|
||||||
class StoreOnlyRoms(NamedTuple):
|
class StoreOnlyRoms(NamedTuple):
|
||||||
rom_ids: dict[int, int]
|
rom_ids: dict[int, int]
|
||||||
created: int
|
created_ids: list[int]
|
||||||
|
|
||||||
|
|
||||||
class DBSteamLibraryHandler(DBBaseHandler):
|
class DBSteamLibraryHandler(DBBaseHandler):
|
||||||
@@ -76,10 +76,10 @@ class DBSteamLibraryHandler(DBBaseHandler):
|
|||||||
"""Insert store-only roms, reusing the row already at a rom's path.
|
"""Insert store-only roms, reusing the row already at a rom's path.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Each app's rom id, and how many rows were inserted.
|
Each app's rom id, and the ids of the rows that were inserted.
|
||||||
"""
|
"""
|
||||||
rom_ids: dict[int, int] = {}
|
rom_ids: dict[int, int] = {}
|
||||||
created = 0
|
created: list[int] = []
|
||||||
for rom in roms:
|
for rom in roms:
|
||||||
app_id = rom.steam_id
|
app_id = rom.steam_id
|
||||||
if app_id is None:
|
if app_id is None:
|
||||||
@@ -105,8 +105,8 @@ class DBSteamLibraryHandler(DBBaseHandler):
|
|||||||
rom_ids[app_id] = existing.id
|
rom_ids[app_id] = existing.id
|
||||||
continue
|
continue
|
||||||
rom_ids[app_id] = rom.id
|
rom_ids[app_id] = rom.id
|
||||||
created += 1
|
created.append(rom.id)
|
||||||
return StoreOnlyRoms(rom_ids=rom_ids, created=created)
|
return StoreOnlyRoms(rom_ids=rom_ids, created_ids=created)
|
||||||
|
|
||||||
@begin_session
|
@begin_session
|
||||||
def get_unmatched_store_only_rom_ids(
|
def get_unmatched_store_only_rom_ids(
|
||||||
|
|||||||
@@ -130,6 +130,17 @@ def _refresh_ownership_collections(user_id: int, app_ids: Sequence[int]) -> None
|
|||||||
log.error(f"Couldn't refresh smart collections for Steam apps {app_ids}: {e}")
|
log.error(f"Couldn't refresh smart collections for Steam apps {app_ids}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def _refresh_library_collections(rom_ids: Sequence[int]) -> None:
|
||||||
|
"""Follow roms added to the library into every smart collection they match."""
|
||||||
|
if not rom_ids:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
db_collection_handler.refresh_smart_collections_for_roms(rom_ids)
|
||||||
|
except Exception as e:
|
||||||
|
# The roms are committed, so a stale count is the worst this costs.
|
||||||
|
log.error(f"Couldn't refresh smart collections for new Steam roms: {e}")
|
||||||
|
|
||||||
|
|
||||||
def _forget_library(user_id: int) -> None:
|
def _forget_library(user_id: int) -> None:
|
||||||
_refresh_ownership_collections(
|
_refresh_ownership_collections(
|
||||||
user_id, db_steam_library_handler.delete_entries(user_id)
|
user_id, db_steam_library_handler.delete_entries(user_id)
|
||||||
@@ -258,7 +269,7 @@ async def sync_steam_library(user: User) -> SteamSyncResult:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
rom_ids.update(store_only.rom_ids)
|
rom_ids.update(store_only.rom_ids)
|
||||||
result.created = store_only.created
|
result.created = len(store_only.created_ids)
|
||||||
|
|
||||||
entries = [
|
entries = [
|
||||||
SteamLibraryEntry(
|
SteamLibraryEntry(
|
||||||
@@ -278,6 +289,7 @@ async def sync_steam_library(user: User) -> SteamSyncResult:
|
|||||||
)
|
)
|
||||||
result.removed = len(changes.removed)
|
result.removed = len(changes.removed)
|
||||||
_refresh_ownership_collections(user.id, [*changes.added, *changes.removed])
|
_refresh_ownership_collections(user.id, [*changes.added, *changes.removed])
|
||||||
|
_refresh_library_collections(store_only.created_ids)
|
||||||
result.unmatched_rom_ids = (
|
result.unmatched_rom_ids = (
|
||||||
db_steam_library_handler.get_unmatched_store_only_rom_ids(
|
db_steam_library_handler.get_unmatched_store_only_rom_ids(
|
||||||
[entry.rom_id for entry in entries]
|
[entry.rom_id for entry in entries]
|
||||||
|
|||||||
@@ -207,6 +207,29 @@ async def test_prefers_a_rom_with_a_file_over_one_without(
|
|||||||
assert entry.rom_id == with_file.id
|
assert entry.rom_id == with_file.id
|
||||||
|
|
||||||
|
|
||||||
|
async def test_imported_games_reach_collections_that_do_not_filter_on_steam(
|
||||||
|
steam_api: MagicMock, steam_user: User, win: Platform
|
||||||
|
):
|
||||||
|
"""A store-only rom is a library row, so it cannot wait on the metadata scan."""
|
||||||
|
collection = db_collection_handler.add_smart_collection(
|
||||||
|
SmartCollection(
|
||||||
|
name="Windows games",
|
||||||
|
description="",
|
||||||
|
user_id=steam_user.id,
|
||||||
|
filter_criteria={"platform_ids": [win.id]},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
db_collection_handler.refresh_smart_collections()
|
||||||
|
seeded = db_collection_handler.get_smart_collection(collection.id)
|
||||||
|
assert seeded is not None and seeded.rom_count == 0
|
||||||
|
steam_api.get_owned_games.return_value = [_game(220, "Half-Life 2")]
|
||||||
|
|
||||||
|
await sync_steam_library(steam_user)
|
||||||
|
|
||||||
|
after = db_collection_handler.get_smart_collection(collection.id)
|
||||||
|
assert after is not None and after.rom_count == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_a_second_sync_reuses_the_store_only_rom(
|
async def test_a_second_sync_reuses_the_store_only_rom(
|
||||||
steam_api: MagicMock, steam_user: User, win: Platform
|
steam_api: MagicMock, steam_user: User, win: Platform
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user