From 4c4b211aaee0e4556abc19f82c02e98cc3e74611 Mon Sep 17 00:00:00 2001 From: Rob Leidle Date: Fri, 9 Aug 2024 15:04:55 -0700 Subject: [PATCH] Move the bulk insert resolve into the COMMIT callback db.db.serialize(...) guarantees that each statement runs in order. However, the function itself will terminate execution long before all the statements are executed. Therefore, we should only resolve the promise when the last COMMIT transaction has run. In the other cases, there will have been an error and we'll have call reject(err). This also removed the need for the extra insert that was recently added so it was removed (in fact the extra insert was causing conflict errors). --- core/indexing/LanceDbIndex.ts | 11 ++--------- core/indexing/chunk/ChunkCodebaseIndex.ts | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index 198232a95..f7f1e6ecc 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -268,14 +268,6 @@ export class LanceDbIndex implements CodebaseIndex { const dbRows = await this.computeRows(results.compute); await this.insertRows(sqlite, dbRows); - await Promise.all( - results.compute.map((item) => { - addComputedLanceDbRows( - item, - dbRows.filter((row) => row.path === item.path), - ); - }), - ); await markComplete(results.compute, IndexResultType.Compute); let accumulatedProgress = 0; @@ -481,9 +473,10 @@ export class LanceDbIndex implements CodebaseIndex { { cause: err }, ), ); + } else { + resolve(); } }); - resolve(); }); }); } diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index 008f90c62..0e866b3bf 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -133,7 +133,6 @@ export class ChunkCodebaseIndex implements CodebaseIndex { } } - private async createTables(db: DatabaseConnection) { await db.exec(`CREATE TABLE IF NOT EXISTS chunks ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -201,9 +200,10 @@ export class ChunkCodebaseIndex implements CodebaseIndex { db.db.exec("COMMIT", (err: Error | null) => { if (err) { reject(new Error("error while committing insert chunks transaction", { cause: err })); + } else { + resolve(); } }); - resolve(); }); }); }