@wrongstack/tools 0.283.0 → 0.283.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2999,6 +2999,24 @@ var IndexStore = class {
2999
2999
  * When false, ranked search falls back to the LIKE + in-process BM25 path.
3000
3000
  */
3001
3001
  ftsAvailable = false;
3002
+ /**
3003
+ * Cache of prepared statements keyed by their SQL text. `DatabaseSync`
3004
+ * compiles SQL on every `.prepare()` call; for the fixed-SQL methods
3005
+ * (upsertFile, getFileMeta, deleteFile, insertRefs, …) that runs thousands
3006
+ * of times during a full reindex. `StatementSync` objects are reusable
3007
+ * across calls on the same connection, so we compile each distinct SQL once
3008
+ * and reuse it. Cleared in {@link close} when the connection is torn down.
3009
+ */
3010
+ stmtCache = /* @__PURE__ */ new Map();
3011
+ /** Prepare-once helper: compile `sql` on first use, reuse thereafter. */
3012
+ stmt(sql) {
3013
+ let s = this.stmtCache.get(sql);
3014
+ if (s === void 0) {
3015
+ s = this.db.prepare(sql);
3016
+ this.stmtCache.set(sql, s);
3017
+ }
3018
+ return s;
3019
+ }
3002
3020
  /**
3003
3021
  * Execute a SQLite write operation with automatic retry on lock conflicts.
3004
3022
  *
@@ -3168,9 +3186,9 @@ var IndexStore = class {
3168
3186
  deleteSymbolsForFile(file) {
3169
3187
  this.runWithRetry(() => {
3170
3188
  if (this.ftsAvailable) {
3171
- this.db.prepare("DELETE FROM symbols_fts WHERE rowid IN (SELECT id FROM symbols WHERE file_fk = ?)").run(file);
3189
+ this.stmt("DELETE FROM symbols_fts WHERE rowid IN (SELECT id FROM symbols WHERE file_fk = ?)").run(file);
3172
3190
  }
3173
- this.db.prepare("DELETE FROM symbols WHERE file_fk = ?").run(file);
3191
+ this.stmt("DELETE FROM symbols WHERE file_fk = ?").run(file);
3174
3192
  });
3175
3193
  }
3176
3194
  /**
@@ -3182,13 +3200,13 @@ var IndexStore = class {
3182
3200
  this.runWithRetry(() => {
3183
3201
  this.deleteRefsForFile(file);
3184
3202
  this.deleteSymbolsForFile(file);
3185
- this.db.prepare("DELETE FROM files WHERE file = ?").run(file);
3203
+ this.stmt("DELETE FROM files WHERE file = ?").run(file);
3186
3204
  });
3187
3205
  }
3188
3206
  // ─── File metadata ──────────────────────────────────────────────────────────
3189
3207
  upsertFile(meta) {
3190
3208
  this.runWithRetry(() => {
3191
- this.db.prepare(
3209
+ this.stmt(
3192
3210
  `INSERT INTO files(file, lang, mtime_ms, symbol_count, last_indexed)
3193
3211
  VALUES (?, ?, ?, ?, ?)
3194
3212
  ON CONFLICT(file) DO UPDATE SET
@@ -3200,7 +3218,7 @@ var IndexStore = class {
3200
3218
  });
3201
3219
  }
3202
3220
  getFileMeta(file) {
3203
- const rows = this.db.prepare(
3221
+ const rows = this.stmt(
3204
3222
  "SELECT file, lang, mtime_ms, symbol_count, last_indexed FROM files WHERE file = ?"
3205
3223
  ).all(file);
3206
3224
  if (!rows.length) return null;
@@ -3423,7 +3441,7 @@ var IndexStore = class {
3423
3441
  */
3424
3442
  insertRefs(fromId, refs) {
3425
3443
  this.runWithRetry(() => {
3426
- this.db.prepare("DELETE FROM refs WHERE from_id = ?").run(fromId);
3444
+ this.stmt("DELETE FROM refs WHERE from_id = ?").run(fromId);
3427
3445
  if (refs.length === 0) return;
3428
3446
  const stmt = this.db.prepare(
3429
3447
  `INSERT INTO refs(from_id, to_name, to_id, call_type, line)
@@ -3624,6 +3642,7 @@ var IndexStore = class {
3624
3642
  }
3625
3643
  }
3626
3644
  close() {
3645
+ this.stmtCache.clear();
3627
3646
  try {
3628
3647
  this.db.close();
3629
3648
  } catch {