diigo-cache: a fill ends at the first page past the data
Seen live: "filled: 168 of 1 pages". diigo's total overstated by 100
(16744 vs 16644), so the walk went on to page 168, which diigo answered
empty with a total ≤ 100; the fill recomputed its page count from that,
ceil(total/100) = 1.
Now a page whose own total says the data ended before it ends the walk,
with the count set to the last page with items ("167 of 167"). Judged
by total, not by items, since the public cache may keep none of a page
that isn't the end. The known-pages estimate ignores zero totals. The
fake answers past-the-end pages as diigo does (no items, total 0).
Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
fd16c7db53
commit
4034fba76b
3 files changed
+22
-5
No files matched your search
@@ -241,11 +241,20 @@ abstract class PagedCache extends DurableObject<CacheEnv> {
|
||||
}
|
||||
try {
|
||||
const page = await this.page(status.nextPage, PAGE_SIZE);
|
||||
const fetched = status.fetched + (page.cached ? 0 : 1);
|
||||
// a page whose own total says the data ended before it (diigo
|
||||
// answers total 0 past the end) ends the walk; the count is the
|
||||
// last page with items. Judged by total, not by items: the
|
||||
// public cache may keep none of a page that isn't the end.
|
||||
if (page.total <= (status.nextPage - 1) * PAGE_SIZE) {
|
||||
status = { ...status, state: "done", pages: status.nextPage - 1, fetched, updatedAt: this.#iso() };
|
||||
break;
|
||||
}
|
||||
status = {
|
||||
...status,
|
||||
nextPage: status.nextPage + 1,
|
||||
pages: Math.max(1, Math.ceil(page.total / PAGE_SIZE)),
|
||||
fetched: status.fetched + (page.cached ? 0 : 1),
|
||||
pages: Math.ceil(page.total / PAGE_SIZE),
|
||||
fetched,
|
||||
updatedAt: this.#iso(),
|
||||
};
|
||||
} catch (err) {
|
||||
@@ -265,11 +274,12 @@ abstract class PagedCache extends DurableObject<CacheEnv> {
|
||||
if (status.state === "running") await this.ctx.storage.setAlarm(this.#clock.now() + FILL_STEP_DELAY_MS);
|
||||
}
|
||||
|
||||
/** diigo's page count, if any cached page recorded `total` */
|
||||
/** diigo's page count, if any cached page recorded `total` (pages past
|
||||
* the end record 0, so they don't count) */
|
||||
#knownPages(): number | null {
|
||||
this.ctx.storage.sql.exec(SCHEMA_V1);
|
||||
const row = this.ctx.storage.sql
|
||||
.exec<{ total: number | null }>("select total from pages where total is not null order by etched_at desc limit 1")
|
||||
.exec<{ total: number | null }>("select total from pages where total > 0 order by etched_at desc limit 1")
|
||||
.toArray();
|
||||
return row.length > 0 && row[0].total !== null ? Math.max(1, Math.ceil(row[0].total / PAGE_SIZE)) : null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user