mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
fix(steam): keep the newest owned list and trim docstrings
A slow earlier request for the owned Steam apps could overwrite a newer reply, so only the latest request now writes. Also trims two docstrings to the one-sentence rule. Addresses Greptile's second review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh
This commit is contained in:
@@ -30,10 +30,7 @@ class DBSteamLibraryHandler(DBBaseHandler):
|
||||
steam_app_ids: Sequence[int],
|
||||
session: Session = INJECTED_SESSION,
|
||||
) -> dict[int, int]:
|
||||
"""The rom that stands for each Steam app on the given platforms.
|
||||
|
||||
A rom with a file wins over a store-only one, then the oldest row.
|
||||
"""
|
||||
"""Each Steam app's rom on the given platforms, preferring one with a file."""
|
||||
rows: list[tuple[int | None, int, str | None]] = []
|
||||
ids = list(steam_app_ids)
|
||||
for start in range(0, len(ids), STEAM_ID_CHUNK_SIZE):
|
||||
|
||||
@@ -192,10 +192,6 @@ def _last_played(game: SteamOwnedGame) -> datetime | None:
|
||||
async def sync_steam_library(user: User) -> SteamSyncResult:
|
||||
"""Make the user's Steam library entries match what their account owns.
|
||||
|
||||
Owned games already in the library are linked to their rom; the rest get a
|
||||
store-only rom. Store-only roms still unmatched are listed for a metadata
|
||||
scan, since a library scan never reaches a game without a file.
|
||||
|
||||
Raises:
|
||||
SteamLibraryError: The account isn't linked, Steam can't list its games,
|
||||
or the account changed during the sync.
|
||||
|
||||
@@ -56,6 +56,29 @@ describe("steamLibrary", () => {
|
||||
expect(library.owns(400)).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the newest reply when an older one arrives late", async () => {
|
||||
let answerFirst: (value: unknown) => void = () => {};
|
||||
vi.mocked(userApi.fetchSteamLibrary)
|
||||
.mockReturnValueOnce(
|
||||
new Promise((resolve) => {
|
||||
answerFirst = resolve;
|
||||
}) as never,
|
||||
)
|
||||
.mockResolvedValueOnce({ data: [400] } as never);
|
||||
storeAuth().setCurrentUser(
|
||||
userFixture({ id: 1, steam_id: "76561197960287930" }),
|
||||
);
|
||||
library = useSteamLibrary();
|
||||
void library.load();
|
||||
await flushPromises();
|
||||
|
||||
answerFirst({ data: [220] });
|
||||
await flushPromises();
|
||||
|
||||
expect(library.owns(400)).toBe(true);
|
||||
expect(library.owns(220)).toBe(false);
|
||||
});
|
||||
|
||||
it("loads nothing without a linked account", async () => {
|
||||
storeAuth().setCurrentUser(userFixture({ id: 1 }));
|
||||
library = useSteamLibrary();
|
||||
|
||||
@@ -27,13 +27,17 @@ const useSteamLibrary = defineStore("steamLibrary", () => {
|
||||
return ownedAppIds.value.has(appId);
|
||||
}
|
||||
|
||||
// Only the newest request may write, so a slow earlier reply can't win.
|
||||
let latestRequest = 0;
|
||||
|
||||
async function load() {
|
||||
const user = auth.user;
|
||||
const requested = account.value;
|
||||
if (!user || !requested) return;
|
||||
const request = ++latestRequest;
|
||||
try {
|
||||
const { data } = await userApi.fetchSteamLibrary({ id: user.id });
|
||||
if (account.value !== requested) return;
|
||||
if (request !== latestRequest || account.value !== requested) return;
|
||||
ownedAppIds.value = new Set(data);
|
||||
loadedFor.value = requested;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user