Add QR codes to cards, stop inventing call number parts
Cards now carry a QR code holding the book's own record (call number, title, authors, ISBN, year), and the scanner reads it back to find or add that book. Call number selection no longer pads catalogue numbers with generated cutters. A number is "exact" only when it comes verbatim from a record for this edition; a bare class is a hint that steers the other-edition and similar-books lookups; a record fetched by LCCN must list the book's ISBN to count as this edition. "Look up again" bypasses every cached result, and shelf order breaks ties by author then title. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cec404e21
commit
ad2956e868
56 files changed
+4020
-156
No files matched your search
+13
-6
@@ -6,7 +6,12 @@ export const DEFAULT_RETRY_DELAYS_MS = [5_000, 30_000, 120_000];
|
||||
|
||||
export type ResolverLike = Resolver;
|
||||
|
||||
export interface Jobs { enqueue(id: number): void; resume(): void; idle(): Promise<void> }
|
||||
export interface Jobs {
|
||||
/** `fresh`: the lookup ignores every cached source answer ("Look up again"), through its retries too. */
|
||||
enqueue(id: number, opts?: { fresh?: boolean }): void;
|
||||
resume(): void;
|
||||
idle(): Promise<void>;
|
||||
}
|
||||
|
||||
// TemporaryError lives in resolve/resolver.ts; match by class name unless the caller injects a test.
|
||||
function defaultIsTemporary(e: unknown): boolean {
|
||||
@@ -35,6 +40,7 @@ export function createJobs(deps: {
|
||||
const queue: number[] = [];
|
||||
const queued = new Set<number>();
|
||||
const attempts = new Map<number, number>();
|
||||
const fresh = new Set<number>();
|
||||
// Books waiting for a retry: they hold no worker; a timer puts them back in the queue.
|
||||
const waiting = new Map<number, ReturnType<typeof setTimeout>>();
|
||||
let running: Promise<void> | null = null;
|
||||
@@ -77,7 +83,7 @@ export function createJobs(deps: {
|
||||
|
||||
async function attempt(id: number): Promise<void> {
|
||||
const book = db.getBook(id);
|
||||
if (!book || book.status !== 'pending') { attempts.delete(id); return; }
|
||||
if (!book || book.status !== 'pending') { attempts.delete(id); fresh.delete(id); return; }
|
||||
const n = attempts.get(id) ?? 0;
|
||||
const final = n >= delays.length;
|
||||
const input: ResolveInput = {};
|
||||
@@ -93,8 +99,8 @@ export function createJobs(deps: {
|
||||
let similar = '';
|
||||
const took = () => `${Date.now() - started} ms`;
|
||||
try {
|
||||
const res = await resolver.resolve(input, { onMeta: (m) => applyMeta(id, m), tolerateLocFailure: final, onSimilar: (d) => { similar = d; } });
|
||||
attempts.delete(id);
|
||||
const res = await resolver.resolve(input, { onMeta: (m) => applyMeta(id, m), tolerateLocFailure: final, fresh: fresh.has(id), onSimilar: (d) => { similar = d; } });
|
||||
attempts.delete(id); fresh.delete(id);
|
||||
const cur = db.getBook(id);
|
||||
if (!cur) return;
|
||||
if (res.meta) applyMeta(id, res.meta);
|
||||
@@ -123,7 +129,7 @@ export function createJobs(deps: {
|
||||
schedule(id, delay);
|
||||
return;
|
||||
}
|
||||
attempts.delete(id);
|
||||
attempts.delete(id); fresh.delete(id);
|
||||
log(`[lookup] ${label}: failed, ${message} in ${took()}`);
|
||||
const cur = db.getBook(id);
|
||||
if (cur && !cur.manualOverride) {
|
||||
@@ -146,7 +152,8 @@ export function createJobs(deps: {
|
||||
}
|
||||
|
||||
return {
|
||||
enqueue(id) {
|
||||
enqueue(id, opts) {
|
||||
if (opts?.fresh) fresh.add(id);
|
||||
// A fresh request (scan, "Look up again") overrides any wait and starts the retries over.
|
||||
const t = waiting.get(id);
|
||||
if (t) { clearTimeout(t); waiting.delete(id); attempts.delete(id); }
|
||||
|
||||
Reference in new issue
Block a user