Drop lock_lines and retire its writer (dead table, dead writer)
lock_lines was built in Session 64 for a staleness audit - join lock-time
per-book lines to closing_captures and ask whether our locked line was
stale-high vs consensus. That audit was never written. ruler-comparison.sql
records why: only 43 settled rows ever joined it with >=2 two-sided books.
Measured before removal: 367,595 rows, 104 MB, zero readers in src/, scripts/
or web/src/ - the only from('lock_lines') was an upsert, every other mention a
comment. Zero dependents: no FK, no view, no trigger. The newest pg_dump held
all 367,595 rows, pg_restore-verified before the drop.
The write is off too, because a dead table that keeps refilling is only half
solved: it was accruing 36,440 rows/day, 10.3 MB/day, 23% of all database
growth, for a question nobody was asking. buildLockRows is kept and still
tested - the logic was never what was wrong, and re-arming is one flag plus
re-creating the table.
DB 510 MB -> 406 MB: 81% of the 500 MB cap, +94 MB headroom, under it for the
first time in months.
Moat and grade untouched.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,23 @@
|
||||
*
|
||||
* HONEST-ABSENT: a graded prop with only one priced book persists as ONE row. Never a
|
||||
* fabricated second book. A book row with neither price is not a line and is skipped.
|
||||
*
|
||||
* ── RETIRED 2026-08-12 (Reclaim 2) — THE AUDIT WAS NEVER WRITTEN ─────────
|
||||
* This table was built in Session 64 to unblock a staleness check: join lock-time
|
||||
* per-book lines to `closing_captures` and ask whether our locked line was
|
||||
* stale-high vs consensus. That join was never written. Measured before removal:
|
||||
* 367,595 rows, 104 MB, **zero readers** anywhere in src/, scripts/ or web/src/ —
|
||||
* the only mentions were this file's own comments and one comment line in
|
||||
* `scripts/ruler-comparison.sql` explaining why the reconstruction was abandoned
|
||||
* (only 43 settled rows ever joined it with >=2 two-sided books).
|
||||
*
|
||||
* It was still accruing 36,440 rows/day — 10.3 MB/day, 23% of all database
|
||||
* growth — for a question nobody was asking. `buildLockRows` is KEPT and still
|
||||
* tested: it is pure, correct, and the moment someone writes that audit the
|
||||
* capture can be re-armed with one flag. What is switched off is the WRITE.
|
||||
*
|
||||
* Set LOCK_LINE_CAPTURE=1 to re-arm. Doing so requires re-creating the table
|
||||
* (migration 033) — it was dropped, and the pg_dump chain holds the history.
|
||||
*/
|
||||
|
||||
const { nameKey, normalizeName } = require('../utils/playerName');
|
||||
@@ -106,8 +123,19 @@ function buildLockRows(sport, props, gradedKeys, opts = {}) {
|
||||
* Persist append-only. Idempotent via the UNIQUE key (a snapshot retry never
|
||||
* double-inserts). Best-effort — a persistence failure never breaks the snapshot.
|
||||
*/
|
||||
/** Re-arm the capture (also needs the table re-created — see the header). */
|
||||
const captureArmed = () => process.env.LOCK_LINE_CAPTURE === '1';
|
||||
|
||||
async function persist(rows, deps = {}) {
|
||||
const out = { attempted: rows ? rows.length : 0, written: 0, skipped: false, error: null };
|
||||
// RETIRED: the table is dropped and nothing reads it. Returning early keeps
|
||||
// every caller's contract intact (a best-effort leaf that reports what it did)
|
||||
// without touching a table that no longer exists.
|
||||
if (!(deps.armed ?? captureArmed())) {
|
||||
out.skipped = true;
|
||||
out.retired = true;
|
||||
return out;
|
||||
}
|
||||
if (!out.attempted) return out;
|
||||
try {
|
||||
const getClient = deps.getClient || require('../utils/supabase').getSupabaseServiceClient;
|
||||
@@ -129,4 +157,4 @@ async function persist(rows, deps = {}) {
|
||||
return out;
|
||||
}
|
||||
|
||||
module.exports = { buildLockRows, persist, lockKey, SHARP_BOOKS };
|
||||
module.exports = { buildLockRows, persist, lockKey, SHARP_BOOKS, captureArmed };
|
||||
|
||||
@@ -691,7 +691,11 @@ async function runSnapshot(sport, opts = {}) {
|
||||
const gradedKeys = new Set(enriched.map((g) => `${norm(g.player || g.player_name)}|${String(g.stat_type || g.stat || '').toLowerCase()}`));
|
||||
const lockRows = deps.lockLineCapture.buildLockRows(sp, props, gradedKeys, { lockedAt: ts });
|
||||
const lr = await deps.lockLineCapture.persist(lockRows);
|
||||
console.log(`[lock-lines] ${sp}: ${lr.written}/${lr.attempted} multi-book rows persisted at lock${lr.skipped ? ' (skipped — no supabase env)' : ''}${lr.error ? ` ERROR: ${lr.error}` : ''}`);
|
||||
// `retired` and `no supabase env` are different states and must read
|
||||
// differently — a retired capture is a decision, a missing env is a fault.
|
||||
console.log(`[lock-lines] ${sp}: ${lr.retired
|
||||
? `RETIRED (table dropped 2026-08-12, zero readers; ${lr.attempted} rows not written)`
|
||||
: `${lr.written}/${lr.attempted} multi-book rows persisted at lock${lr.skipped ? ' (skipped — no supabase env)' : ''}`}${lr.error ? ` ERROR: ${lr.error}` : ''}`);
|
||||
} catch (e) {
|
||||
console.warn(`[lock-lines] ${sp} persist failed (measurement-only, snapshot continues):`, e.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user