@wrongstack/tools 0.282.2 → 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.
@@ -52,6 +52,17 @@ declare class IndexStore {
52
52
  * When false, ranked search falls back to the LIKE + in-process BM25 path.
53
53
  */
54
54
  private ftsAvailable;
55
+ /**
56
+ * Cache of prepared statements keyed by their SQL text. `DatabaseSync`
57
+ * compiles SQL on every `.prepare()` call; for the fixed-SQL methods
58
+ * (upsertFile, getFileMeta, deleteFile, insertRefs, …) that runs thousands
59
+ * of times during a full reindex. `StatementSync` objects are reusable
60
+ * across calls on the same connection, so we compile each distinct SQL once
61
+ * and reuse it. Cleared in {@link close} when the connection is torn down.
62
+ */
63
+ private readonly stmtCache;
64
+ /** Prepare-once helper: compile `sql` on first use, reuse thereafter. */
65
+ private stmt;
55
66
  /**
56
67
  * Execute a SQLite write operation with automatic retry on lock conflicts.
57
68
  *
@@ -312,6 +312,24 @@ var IndexStore = class {
312
312
  * When false, ranked search falls back to the LIKE + in-process BM25 path.
313
313
  */
314
314
  ftsAvailable = false;
315
+ /**
316
+ * Cache of prepared statements keyed by their SQL text. `DatabaseSync`
317
+ * compiles SQL on every `.prepare()` call; for the fixed-SQL methods
318
+ * (upsertFile, getFileMeta, deleteFile, insertRefs, …) that runs thousands
319
+ * of times during a full reindex. `StatementSync` objects are reusable
320
+ * across calls on the same connection, so we compile each distinct SQL once
321
+ * and reuse it. Cleared in {@link close} when the connection is torn down.
322
+ */
323
+ stmtCache = /* @__PURE__ */ new Map();
324
+ /** Prepare-once helper: compile `sql` on first use, reuse thereafter. */
325
+ stmt(sql) {
326
+ let s = this.stmtCache.get(sql);
327
+ if (s === void 0) {
328
+ s = this.db.prepare(sql);
329
+ this.stmtCache.set(sql, s);
330
+ }
331
+ return s;
332
+ }
315
333
  /**
316
334
  * Execute a SQLite write operation with automatic retry on lock conflicts.
317
335
  *
@@ -481,9 +499,9 @@ var IndexStore = class {
481
499
  deleteSymbolsForFile(file) {
482
500
  this.runWithRetry(() => {
483
501
  if (this.ftsAvailable) {
484
- this.db.prepare("DELETE FROM symbols_fts WHERE rowid IN (SELECT id FROM symbols WHERE file_fk = ?)").run(file);
502
+ this.stmt("DELETE FROM symbols_fts WHERE rowid IN (SELECT id FROM symbols WHERE file_fk = ?)").run(file);
485
503
  }
486
- this.db.prepare("DELETE FROM symbols WHERE file_fk = ?").run(file);
504
+ this.stmt("DELETE FROM symbols WHERE file_fk = ?").run(file);
487
505
  });
488
506
  }
489
507
  /**
@@ -495,13 +513,13 @@ var IndexStore = class {
495
513
  this.runWithRetry(() => {
496
514
  this.deleteRefsForFile(file);
497
515
  this.deleteSymbolsForFile(file);
498
- this.db.prepare("DELETE FROM files WHERE file = ?").run(file);
516
+ this.stmt("DELETE FROM files WHERE file = ?").run(file);
499
517
  });
500
518
  }
501
519
  // ─── File metadata ──────────────────────────────────────────────────────────
502
520
  upsertFile(meta) {
503
521
  this.runWithRetry(() => {
504
- this.db.prepare(
522
+ this.stmt(
505
523
  `INSERT INTO files(file, lang, mtime_ms, symbol_count, last_indexed)
506
524
  VALUES (?, ?, ?, ?, ?)
507
525
  ON CONFLICT(file) DO UPDATE SET
@@ -513,7 +531,7 @@ var IndexStore = class {
513
531
  });
514
532
  }
515
533
  getFileMeta(file) {
516
- const rows = this.db.prepare(
534
+ const rows = this.stmt(
517
535
  "SELECT file, lang, mtime_ms, symbol_count, last_indexed FROM files WHERE file = ?"
518
536
  ).all(file);
519
537
  if (!rows.length) return null;
@@ -736,7 +754,7 @@ var IndexStore = class {
736
754
  */
737
755
  insertRefs(fromId, refs) {
738
756
  this.runWithRetry(() => {
739
- this.db.prepare("DELETE FROM refs WHERE from_id = ?").run(fromId);
757
+ this.stmt("DELETE FROM refs WHERE from_id = ?").run(fromId);
740
758
  if (refs.length === 0) return;
741
759
  const stmt = this.db.prepare(
742
760
  `INSERT INTO refs(from_id, to_name, to_id, call_type, line)
@@ -937,6 +955,7 @@ var IndexStore = class {
937
955
  }
938
956
  }
939
957
  close() {
958
+ this.stmtCache.clear();
940
959
  try {
941
960
  this.db.close();
942
961
  } catch {