MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / runBatched

Method runBatched

src/db/queries.ts:264–288  ·  view source on GitHub ↗

* Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`, * decomposed greedily into the cached batch sizes. Preserves row order.

(kind: string, head: string, tuple: string, rows: unknown[][])

Source from the content-addressed store, hash-verified

262 * decomposed greedily into the cached batch sizes. Preserves row order.
263 */
264 private runBatched(kind: string, head: string, tuple: string, rows: unknown[][]): void {
265 if (rows.length === 0) return;
266 let i = 0;
267 for (const size of QueryBuilder.BATCH_SIZES) {
268 while (rows.length - i >= size) {
269 const key = `${kind}:${size}`;
270 let stmt = this.batchStmts.get(key);
271 if (!stmt) {
272 stmt = this.db.prepare(head + new Array(size).fill(tuple).join(','));
273 this.batchStmts.set(key, stmt);
274 }
275 if (size === 1) {
276 stmt.run(...rows[i]!);
277 } else {
278 const params: unknown[] = [];
279 for (let r = 0; r < size; r++) {
280 const row = rows[i + r]!;
281 for (let c = 0; c < row.length; c++) params.push(row[c]);
282 }
283 stmt.run(...params);
284 }
285 i += size;
286 }
287 }
288 }
289
290 constructor(db: SqliteDatabase) {
291 this.db = db;

Callers 6

insertNameSegmentsMethod · 0.95
insertNodesMethod · 0.95
storeFileBundleMethod · 0.95
insertEdgesMethod · 0.95

Calls 5

getMethod · 0.65
prepareMethod · 0.65
runMethod · 0.65
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected