Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Keep the contributor-triggered calibration read indexed after login casing canonicalization (#2349).
-- SQLite/D1 cannot use the plain (login, created_at) index for WHERE lower(login) = ?, so this matching
-- expression index preserves case-insensitive lookup semantics without scanning the insert-only ledger.
CREATE INDEX IF NOT EXISTS predicted_gate_calibration_ledger_login_lower_idx
ON predicted_gate_calibration_ledger(lower(login), created_at);
20 changes: 20 additions & 0 deletions test/unit/predicted-gate-calibration-ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ describe("computeContributorCalibration — per-login calibration read (#2349)",
expect(await computeContributorCalibration(env, "someone-else")).toEqual({ sampleSize: 1, agreementRate: 1 });
});

it("uses the matching lower(login) expression index for canonicalized calibration lookups", async () => {
const env = createTestEnv();

const idx = await env.DB.prepare("SELECT name FROM sqlite_master WHERE type='index' AND name = ?")
.bind("predicted_gate_calibration_ledger_login_lower_idx")
.first<{ name: string }>();
expect(idx?.name).toBe("predicted_gate_calibration_ledger_login_lower_idx");

const plan = await env.DB.prepare(
`EXPLAIN QUERY PLAN SELECT COUNT(*) AS sampleSize, COALESCE(AVG(agreed), 0) AS agreementRate
FROM predicted_gate_calibration_ledger
WHERE lower(login) = ?`,
)
.bind("octocat")
.all<{ detail: string }>();
const detail = (plan.results ?? []).map((row) => row.detail).join(" ");
expect(detail).toContain("predicted_gate_calibration_ledger_login_lower_idx");
expect(detail).not.toContain("SCAN predicted_gate_calibration_ledger");
});

it("aggregates across ALL of a login's history regardless of which repo each pairing came from", async () => {
const env = createTestEnv();
await seedLedgerRow(env, { login: "octocat", project: "owner/repo-a", pullNumber: 1, agreed: true });
Expand Down
Loading