diff --git a/packages/loopover-miner/lib/policy-doc-cache.js b/packages/loopover-miner/lib/policy-doc-cache.js index 6abb490f9a..5cfd206c78 100644 --- a/packages/loopover-miner/lib/policy-doc-cache.js +++ b/packages/loopover-miner/lib/policy-doc-cache.js @@ -1,4 +1,4 @@ -import { normalizeLocalStoreDbPath, openLocalStoreDb, resolveLocalStoreDbPath } from "./local-store.js"; +import { normalizeLocalStoreDbPath, openLocalStoreAdapter, resolveLocalStoreDbPath } from "./local-store.js"; import { applySchemaMigrations } from "./schema-version.js"; // Local ETag cache for discovery's small policy-doc fetches (#4842). `discover` refetches each target repo's @@ -30,10 +30,14 @@ function normalizeUrl(url) { /** * Opens the 100% local/client-side miner policy-doc ETag cache. The database only lives on this machine; this * module never uploads, syncs, or phones home with its contents. (#4842) + * + * Opened through the #7175 SqliteDriver seam (`openLocalStoreAdapter`): CRUD goes through `driver.query`, + * while schema creation/migrations still use the underlying DatabaseSync until those helpers are migrated. + * Public API stays synchronous so callers need no async cascade in this part-1 slice. */ export function initPolicyDocCacheStore(dbPath = resolvePolicyDocCacheDbPath()) { const resolvedPath = normalizeDbPath(dbPath); - const db = openLocalStoreDb(resolvedPath); + const { db, driver } = openLocalStoreAdapter(resolvedPath); db.exec(` CREATE TABLE IF NOT EXISTS policy_doc_cache ( url TEXT PRIMARY KEY, @@ -45,22 +49,23 @@ export function initPolicyDocCacheStore(dbPath = resolvePolicyDocCacheDbPath()) // Schema-version convention (#4832): stamp the baseline and run any post-baseline migrations (none yet). applySchemaMigrations(db, []); - const getStatement = db.prepare("SELECT etag, content FROM policy_doc_cache WHERE url = ?"); - const putStatement = db.prepare(` + const getSql = "SELECT etag, content FROM policy_doc_cache WHERE url = ?"; + const putSql = ` INSERT INTO policy_doc_cache (url, etag, content, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT(url) DO UPDATE SET etag = excluded.etag, content = excluded.content, updated_at = excluded.updated_at - `); + `; return { dbPath: resolvedPath, /** The last-known `{ etag, content }` for a policy-doc URL, or null when it has never been cached. Both columns * are `TEXT NOT NULL`, so a present row always carries string values. */ get(url) { - const row = getStatement.get(normalizeUrl(url)); + const { rows } = driver.query(getSql, [normalizeUrl(url)]); + const row = rows[0]; return row ? { etag: row.etag, content: row.content } : null; }, /** Record the fresh ETag + body so the next run can revalidate it with a conditional GET. */ @@ -69,7 +74,7 @@ export function initPolicyDocCacheStore(dbPath = resolvePolicyDocCacheDbPath()) if (typeof etag !== "string" || !etag.trim()) throw new Error("invalid_policy_doc_etag"); if (typeof content !== "string") throw new Error("invalid_policy_doc_content"); const updatedAt = new Date().toISOString(); - putStatement.run(normalizedUrl, etag, content, updatedAt); + driver.query(putSql, [normalizedUrl, etag, content, updatedAt]); return { url: normalizedUrl, etag, content, updatedAt }; }, close() {