diigo-cache: page size 100, diigo's cap; fill jobs record their page size
Asked for 128, diigo returned 100 (the short-page guard caught it on the
first real fill), so PAGE_SIZE = 100: ~168 pages for 16.7k bookmarks.
The same run showed a fill job outliving a page-size change: progress
counted in 24s ("page 25 of 698") resumed as if counted in 128s. Stored
state reinterpreted, so: FillStatus records pageSize (additive; jobs
saved without it counted in 24), and a job whose size differs from
PAGE_SIZE fails with "page size changed …; start the fill again"
instead of resuming; starting again replaces it. Tested with the old
shape in storage.
Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
3baffcab4c
commit
563cb83995
4 files changed
+60
-20
No files matched your search
@@ -26,7 +26,7 @@ describe("PublicCache", () => {
|
||||
const before = await testEnv.WEBAPP.calls();
|
||||
const miss = await stub.page(1, 24);
|
||||
expect(miss.cached).toBe(false);
|
||||
expect(miss.total).toBe(300);
|
||||
expect(miss.total).toBe(250);
|
||||
// diigo page 1 = items 1..24, of which 8 are private
|
||||
expect(parse(miss.items).map((i) => i.private)).toEqual(Array(16).fill(false));
|
||||
const afterMiss = await testEnv.WEBAPP.calls();
|
||||
@@ -78,7 +78,7 @@ describe("page size", () => {
|
||||
// settle the RPC promise ourselves: expect().rejects on a DO stub's
|
||||
// promise leaves the rejection unhandled
|
||||
const failure = () => stub.page(1, PAGE_SIZE).then(() => null, (e: unknown) => String(e));
|
||||
expect(await failure()).toMatch(/returned 100 items for page 1 of 3 \(asked for 128\)/);
|
||||
expect(await failure()).toMatch(/returned 64 items for page 1 of 3 \(asked for 100\)/);
|
||||
expect(spy.mock.calls.map((c) => c[0]).filter((e) => e?.outcome === "short-page")).toHaveLength(1);
|
||||
// nothing was stored: asking again refuses again
|
||||
expect(await failure()).toMatch(/page size not honored/);
|
||||
@@ -90,7 +90,7 @@ describe("page size", () => {
|
||||
it("the last page may be short", async () => {
|
||||
const stub = testEnv.CACHE_DO.get(testEnv.CACHE_DO.newUniqueId());
|
||||
await stub.setup({ webappId: WEBAPP_ID });
|
||||
expect((await stub.page(3, PAGE_SIZE)).items).toHaveLength(300 - 2 * PAGE_SIZE);
|
||||
expect((await stub.page(3, PAGE_SIZE)).items).toHaveLength(250 - 2 * PAGE_SIZE);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -153,7 +153,7 @@ describe("worker routes", () => {
|
||||
expect(html).toContain("<strong>cache: MISS");
|
||||
const again = await (await call(`/public/${username}?page=2`)).text();
|
||||
expect(again).toContain("<strong>cache: HIT");
|
||||
// PAGE_SIZE 128: page 2 is bookmarks 129..256
|
||||
// PAGE_SIZE 100: page 2 is bookmarks 101..200
|
||||
expect(html).toContain(">bookmark 130<");
|
||||
// the date comes first, in toISOString() form
|
||||
expect(html).toMatch(/<li><time datetime="\d{4}-\d\d-\d\dT[\d:.]+Z">[^<]+<\/time> <a /);
|
||||
@@ -163,7 +163,7 @@ describe("worker routes", () => {
|
||||
await call(`/public/${username}?page=2`, { headers: { accept: "application/json" } })
|
||||
).json()) as { pages: number; items: unknown[] };
|
||||
expect(json.pages).toBe(3);
|
||||
expect(json.items).toHaveLength(85); // 129..256 minus its 43 multiples of 3
|
||||
expect(json.items).toHaveLength(67); // 101..200 minus its 33 multiples of 3
|
||||
});
|
||||
|
||||
it("publishes a private cache later, without the cache id in the URL", async () => {
|
||||
@@ -278,7 +278,7 @@ describe.skip("public page filters (goal 1d)", () => {
|
||||
body: JSON.stringify({ webappId: "fake-deep-webapp", mode: "public" }),
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
// deep_dee: 47 diigo pages of 128; a search matching nothing must walk them all
|
||||
// deep_dee: 60 diigo pages of 100; a search matching nothing must walk them all
|
||||
const before = await testEnv.WEBAPP.calls();
|
||||
const first = await call("/public/deep_dee?q=nomatch", { headers: { accept: "application/json" } });
|
||||
expect(await first.json()).toMatchObject({ complete: false, items: [] });
|
||||
@@ -305,8 +305,8 @@ describe.skip("public page filters (goal 1d)", () => {
|
||||
body: JSON.stringify({ webappId: "fake-deep-webapp", mode: "public" }),
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
// deep_dee: 6000 bookmarks, one a day, 47 diigo pages of 128; a week
|
||||
// ~14 years back sits near page 40 — a walk from page 1 would cost ~40
|
||||
// deep_dee: 6000 bookmarks, one a day, 60 diigo pages of 100; a week
|
||||
// ~14 years back sits near page 51 — a walk from page 1 would cost ~51
|
||||
const longAgo = new Date(Date.now() - 5100 * 24 * 60 * 60 * 1000);
|
||||
const week = isoWeek(longAgo);
|
||||
const before = await testEnv.WEBAPP.calls();
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
/**
|
||||
* @file a stand-in for webapp's `WebAppFactory` entrypoint, for tests: an
|
||||
* auxiliary worker (plain JS — the vitest pool doesn't transform aux
|
||||
* workers) serving diigo-shaped `load_user_items` pages. 300 items (3
|
||||
* pages of 128), every third private; a few webapp ids are known. Counts its diigo calls so tests
|
||||
* workers) serving diigo-shaped `load_user_items` pages. 250 items (3
|
||||
* pages of 100, the last short), every third private; a few webapp ids
|
||||
* are known. Counts its diigo calls so tests
|
||||
* can tell a cache hit (no call) from a miss.
|
||||
*/
|
||||
import { RpcTarget, WorkerEntrypoint } from "cloudflare:workers";
|
||||
|
||||
const KNOWN_WEBAPP = "fake-webapp-id";
|
||||
const TOTAL = 300;
|
||||
/** the plain account, but diigo-style capped at 100 items per page */
|
||||
const TOTAL = 250;
|
||||
/** the plain account, capped below PAGE_SIZE (as diigo caps at 100) */
|
||||
const CAPPED_WEBAPP = "fake-capped-webapp";
|
||||
const CAP = 100;
|
||||
const CAP = 64;
|
||||
|
||||
/** a second account, for date filters (goal 1d): 60 bookmarks, item n
|
||||
* updated n-1 days + 1 hour before the call, in diigo's updated-desc
|
||||
@@ -19,7 +20,7 @@ const CAP = 100;
|
||||
* 5th an old bookmark edited recently (created 100 days before updated) */
|
||||
const DATED_WEBAPP = "fake-dated-webapp";
|
||||
const DATED_TOTAL = 60;
|
||||
/** the same shape, 6000 deep (~16 years, 47 pages of 128): for walk cost */
|
||||
/** the same shape, 6000 deep (~16 years, 60 pages of 100): for walk cost */
|
||||
const DEEP_WEBAPP = "fake-deep-webapp";
|
||||
const DEEP_TOTAL = 6000;
|
||||
const HOUR = 60 * 60 * 1000;
|
||||
@@ -41,7 +42,8 @@ function datedItem(n, now, user = "dated_dan") {
|
||||
|
||||
/** item n (1-based, in diigo's order): diigo's field names, made-up
|
||||
* values. link_id and updated_at are scrambled (distinct; 7 and 11 are
|
||||
* coprime to 307, a prime above TOTAL), so neither column sorts back into diigo's order — a
|
||||
* coprime to 307, a prime above TOTAL), so neither column sorts back
|
||||
* into diigo's order — a
|
||||
* cache that replays by column rather than by fetch order is caught. */
|
||||
function item(n) {
|
||||
return {
|
||||
|
||||
@@ -9,8 +9,8 @@ import { FIXED_NOW } from "./test-worker.js";
|
||||
import { PAGE_SIZE } from "../src/cache.js";
|
||||
|
||||
// goal 1e (capsite checklist): a job that grabs every page. Fake
|
||||
// accounts: tests/fake-webapp.js ("fake-webapp-id": 300 items = 3 pages
|
||||
// of PAGE_SIZE 128, every 3rd private).
|
||||
// accounts: tests/fake-webapp.js ("fake-webapp-id": 250 items = 3 pages
|
||||
// of PAGE_SIZE 100, every 3rd private).
|
||||
|
||||
type TestEnv = {
|
||||
CACHE_DO: DurableObjectNamespace<import("../src/index.js").DiigoCache>;
|
||||
@@ -131,6 +131,21 @@ describe("fill job (goal 1e)", () => {
|
||||
expect(status?.error).toMatch(/page size not honored/);
|
||||
});
|
||||
|
||||
it("a job saved under another page size fails instead of resuming; a new start replaces it", async () => {
|
||||
const stub = await wired();
|
||||
// the shape a 24-per-page job left in storage (no pageSize field)
|
||||
await runInDurableObject(stub, async (_obj, state) => {
|
||||
const at = new Date().toISOString();
|
||||
await state.storage.put("fill", { state: "running", nextPage: 25, pages: 698, fetched: 23, startedAt: at, updatedAt: at });
|
||||
await state.storage.setAlarm(Date.now() + 60_000);
|
||||
});
|
||||
await drain(stub);
|
||||
const stale = await stub.fillStatus();
|
||||
expect(stale?.state).toBe("failed");
|
||||
expect(stale?.error).toMatch(/page size changed \(from 24 to 100\)/);
|
||||
expect(await stub.startFill()).toMatchObject({ state: "running", nextPage: 1, pageSize: PAGE_SIZE });
|
||||
});
|
||||
|
||||
it("a public cache's fill stores no private rows", async () => {
|
||||
const stub = testEnv.PUBLIC_DO.get(testEnv.PUBLIC_DO.newUniqueId());
|
||||
await stub.setup({ webappId: "fake-webapp-id" });
|
||||
|
||||
Reference in new issue
Block a user