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).
This commit is contained in:
Rob Leidle 2024-08-09 15:04:55 -07:00
parent d9efc11193
commit 4c4b211aae
2 changed files with 4 additions and 11 deletions

View file

@ -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();
});
});
}

View file

@ -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();
});
});
}