@bobfrankston/mailx-store 0.1.43 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/db.d.ts +10 -0
  2. package/db.js +34 -0
  3. package/package.json +1 -1
package/db.d.ts CHANGED
@@ -375,6 +375,16 @@ export declare class MailxDB {
375
375
  uid: number;
376
376
  folderId: number;
377
377
  }[];
378
+ /** Record a prefetch failure (0-body fetch / store-write fail) for a UID,
379
+ * incrementing its backoff count. Persisted so it survives restarts. */
380
+ recordPrefetchFailure(accountId: string, folderId: number, uid: number): void;
381
+ /** Read a UID's prefetch-failure record (count + lastTried), or null. */
382
+ getPrefetchFailure(accountId: string, folderId: number, uid: number): {
383
+ count: number;
384
+ lastTried: number;
385
+ } | null;
386
+ /** Clear a UID's prefetch-failure record after a successful fetch. */
387
+ clearPrefetchFailure(accountId: string, folderId: number, uid: number): void;
378
388
  /** Highest server UID we've seen in this folder. After the
379
389
  * message_folders refactor, this reads from the membership table
380
390
  * rather than messages.uid — a server-side move from this folder
package/db.js CHANGED
@@ -315,6 +315,23 @@ const SCHEMA = `
315
315
  PRIMARY KEY(scope, key)
316
316
  );
317
317
 
318
+ -- Prefetch-failure backoff, PERSISTED (was an in-memory Map that every
319
+ -- daemon restart wiped — so un-fetchable "ghost" UIDs, e.g. stale Outbox
320
+ -- rows for already-sent messages that return 0 bodies, got re-tried in
321
+ -- full on every launch and re-clogged the size-asc prefetch queue,
322
+ -- starving healthy folders. "So much unfetched, never drains" — Bob
323
+ -- 2026-06-01. Persisting the count+timestamp lets the 5min→12h backoff
324
+ -- survive restarts so zombies stay sidelined. Pure cache-control state;
325
+ -- safe to lose (worst case = one extra retry), so no reconstruction needed.
326
+ CREATE TABLE IF NOT EXISTS prefetch_failures (
327
+ account_id TEXT NOT NULL,
328
+ folder_id INTEGER NOT NULL,
329
+ uid INTEGER NOT NULL,
330
+ count INTEGER NOT NULL,
331
+ last_tried INTEGER NOT NULL,
332
+ PRIMARY KEY(account_id, folder_id, uid)
333
+ );
334
+
318
335
  -- Audit trail of every destructive DB operation. Writes ONLY — the row
319
336
  -- inserted here records the deletion the caller is about to (or just
320
337
  -- did) commit on the messages table. Lets the user retroactively answer
@@ -2017,6 +2034,23 @@ export class MailxDB {
2017
2034
  : "";
2018
2035
  return this.db.prepare(`SELECT uid, folder_id as folderId FROM messages WHERE account_id = ? AND (body_path IS NULL OR body_path = '')${exclusion} ORDER BY (size IS NULL OR size = 0), size ASC, date DESC LIMIT ?`).all(accountId, ...excludeFolderIds, limit);
2019
2036
  }
2037
+ /** Record a prefetch failure (0-body fetch / store-write fail) for a UID,
2038
+ * incrementing its backoff count. Persisted so it survives restarts. */
2039
+ recordPrefetchFailure(accountId, folderId, uid) {
2040
+ this.db.prepare(`INSERT INTO prefetch_failures (account_id, folder_id, uid, count, last_tried)
2041
+ VALUES (?, ?, ?, 1, ?)
2042
+ ON CONFLICT(account_id, folder_id, uid)
2043
+ DO UPDATE SET count = count + 1, last_tried = excluded.last_tried`).run(accountId, folderId, uid, Date.now());
2044
+ }
2045
+ /** Read a UID's prefetch-failure record (count + lastTried), or null. */
2046
+ getPrefetchFailure(accountId, folderId, uid) {
2047
+ const r = this.db.prepare("SELECT count, last_tried AS lastTried FROM prefetch_failures WHERE account_id = ? AND folder_id = ? AND uid = ?").get(accountId, folderId, uid);
2048
+ return r ? { count: r.count, lastTried: r.lastTried } : null;
2049
+ }
2050
+ /** Clear a UID's prefetch-failure record after a successful fetch. */
2051
+ clearPrefetchFailure(accountId, folderId, uid) {
2052
+ this.db.prepare("DELETE FROM prefetch_failures WHERE account_id = ? AND folder_id = ? AND uid = ?").run(accountId, folderId, uid);
2053
+ }
2020
2054
  /** Highest server UID we've seen in this folder. After the
2021
2055
  * message_folders refactor, this reads from the membership table
2022
2056
  * rather than messages.uid — a server-side move from this folder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-store",
3
- "version": "0.1.43",
3
+ "version": "0.1.44",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",