fix: page a Thangs collection to the end without a total

A collection answer without totalCount stopped after its first page, so syncs missed every model past 50.
This commit is contained in:
Tautvydas Derzinskas committed 2026-10-20 00:02:34 +02:00
1 parent 87db3f0ff0
commit 68a1481707
2 files changed
+15 -1

No files matched your search

+2 -1
View File
@@ -488,7 +488,8 @@ export async function fetchThangsCollection(
};
const items = records(data.items);
models.push(...items);
if (items.length < PAGE_SIZE || models.length >= info.modelCount) break;
// A total only stops it when the answer gives one; a short page always does.
if (items.length < PAGE_SIZE || (info.modelCount > 0 && models.length >= info.modelCount)) break;
}
if (!info) return null;
return { ...listingOf(models, owned, maxItems), info };
+13
View File
@@ -338,6 +338,19 @@ describe("Thangs listings", () => {
expect(calls.map((call) => call.query.get("page"))).toEqual(["0", "1"]);
expect(calls[0].query.get("isLoggedIn")).toBe("true");
// Without a total, it pages on until a short page.
const untold = stubApi({
"/collections/493183": (call) =>
json({
id: "493183",
name: "Thangs collection",
items:
call.query.get("page") === "0" ? Array.from({ length: 50 }, (_, i) => item(String(i + 1))) : [item("51")],
}),
});
expect((await fetchThangsCollection("493183", ACCESS, new Set()))?.entries).toHaveLength(51);
expect(untold).toHaveLength(2);
stubApi({ "/collections/1": () => json({ message: "Collection is private" }, 403) });
await expect(fetchThangsCollection("1", null, new Set())).rejects.toBeInstanceOf(ThangsPrivateCollectionError);