Skip to content

Commit 9b830b4

Browse files
committed
feat(miner): roll the SqliteDriver seam onto the non-transactional local stores
1 parent 2347f2b commit 9b830b4

11 files changed

Lines changed: 259 additions & 74 deletions

packages/loopover-miner/lib/contribution-profile-cache.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export type ContributionProfileCache = {
1515
export declare function resolveContributionProfileCacheDbPath(env?: Record<string, string | undefined>): string;
1616
/**
1717
* Open the 100%-local contribution-profile cache. The DB only lives on this machine (#6797).
18+
*
19+
* Opened through the #7175 SqliteDriver seam (`openLocalStoreAdapter`): CRUD goes through `driver.query`,
20+
* while schema creation/migrations and the repo-scoped purge still use the underlying DatabaseSync until those
21+
* helpers are migrated. Public API stays synchronous so callers need no async cascade in this part-1 slice.
1822
*/
1923
export declare function initContributionProfileCache(dbPath?: string): ContributionProfileCache;
2024
export declare function getCachedContributionProfile(repoFullName: string, nowMs?: number): CachedContributionProfile | null;

packages/loopover-miner/lib/contribution-profile-cache.js

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/loopover-miner/lib/contribution-profile-cache.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "./contribution-profile.js";
1111
import {
1212
normalizeLocalStoreDbPath,
13-
openLocalStoreDb,
13+
openLocalStoreAdapter,
1414
resolveLocalStoreDbPath,
1515
} from "./local-store.js";
1616
import { applySchemaMigrations } from "./schema-version.js";
@@ -63,12 +63,16 @@ function normalizeRepoFullName(repoFullName: unknown): string {
6363

6464
/**
6565
* Open the 100%-local contribution-profile cache. The DB only lives on this machine (#6797).
66+
*
67+
* Opened through the #7175 SqliteDriver seam (`openLocalStoreAdapter`): CRUD goes through `driver.query`,
68+
* while schema creation/migrations and the repo-scoped purge still use the underlying DatabaseSync until those
69+
* helpers are migrated. Public API stays synchronous so callers need no async cascade in this part-1 slice.
6670
*/
6771
export function initContributionProfileCache(
6872
dbPath: string = resolveContributionProfileCacheDbPath(),
6973
): ContributionProfileCache {
7074
const resolvedPath = normalizeDbPath(dbPath);
71-
const db = openLocalStoreDb(resolvedPath);
75+
const { db, driver } = openLocalStoreAdapter(resolvedPath);
7276
db.exec(`
7377
CREATE TABLE IF NOT EXISTS ${CONTRIBUTION_PROFILE_STORE_TABLE} (
7478
repo_full_name TEXT PRIMARY KEY,
@@ -79,16 +83,14 @@ export function initContributionProfileCache(
7983
// Schema-version convention (#4832): stamp the baseline. No post-baseline migrations for this v1 store yet.
8084
applySchemaMigrations(db, []);
8185

82-
const getStatement = db.prepare(
83-
`SELECT profile_json, fetched_at FROM ${CONTRIBUTION_PROFILE_STORE_TABLE} WHERE repo_full_name = ?`,
84-
);
85-
const putStatement = db.prepare(`
86+
const getSql = `SELECT profile_json, fetched_at FROM ${CONTRIBUTION_PROFILE_STORE_TABLE} WHERE repo_full_name = ?`;
87+
const putSql = `
8688
INSERT INTO ${CONTRIBUTION_PROFILE_STORE_TABLE} (repo_full_name, profile_json, fetched_at)
8789
VALUES (?, ?, ?)
8890
ON CONFLICT(repo_full_name) DO UPDATE SET
8991
profile_json = excluded.profile_json,
9092
fetched_at = excluded.fetched_at
91-
`);
93+
`;
9294

9395
return {
9496
dbPath: resolvedPath,
@@ -98,7 +100,7 @@ export function initContributionProfileCache(
98100
* miss (fail closed) rather than throwing — a corrupted/hand-edited file must not break discover.
99101
*/
100102
get(repoFullName: string, nowMs: number = Date.now()): CachedContributionProfile | null {
101-
const row = getStatement.get(normalizeRepoFullName(repoFullName)) as
103+
const row = driver.query(getSql, [normalizeRepoFullName(repoFullName)]).rows[0] as
102104
| { profile_json: string; fetched_at: string }
103105
| undefined;
104106
if (!row) return null;
@@ -121,7 +123,7 @@ export function initContributionProfileCache(
121123
put(profile: ContributionProfile, nowMs: number = Date.now()): { repoFullName: string; fetchedAt: string } {
122124
const repoFullName = normalizeRepoFullName(profile?.repoFullName);
123125
const fetchedAt = new Date(nowMs).toISOString();
124-
putStatement.run(repoFullName, JSON.stringify(profile), fetchedAt);
126+
driver.query(putSql, [repoFullName, JSON.stringify(profile), fetchedAt]);
125127
return { repoFullName, fetchedAt };
126128
},
127129
/**

packages/loopover-miner/lib/policy-verdict-cache.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ export declare function resolvePolicyVerdictCacheDbPath(env?: Record<string, str
2525
/**
2626
* Opens the 100% local/client-side miner policy-verdict cache. The database only lives on this machine; this
2727
* module never uploads, syncs, or phones home with its contents. (#4843)
28+
*
29+
* Opened through the #7175 SqliteDriver seam (`openLocalStoreAdapter`): CRUD goes through `driver.query`,
30+
* while schema creation/migrations and the repo-scoped purge still use the underlying DatabaseSync until those
31+
* helpers are migrated. Public API stays synchronous so callers need no async cascade in this part-1 slice.
2832
*/
2933
export declare function initPolicyVerdictCacheStore(dbPath?: string): PolicyVerdictCacheStore;

0 commit comments

Comments
 (0)