Change ChunkCodebaseIndex to add a tag for known chunks rather than rechunking the file (#1926)

Note that the prior logic referenced the wrong file contents so it was
likely impacting the accuracy of portions of the index that use the
chunks table.

Co-authored-by: Rob Leidle <rleidle@tesla.com>
This commit is contained in:
Rob Leidle 2024-08-05 16:39:12 -07:00 • committed by GitHub
parent e93ce84cd5
commit 30db947c77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -129,29 +129,20 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
}
// Add tag
const addContents = await Promise.all(
results.addTag.map(({ path }) => this.readFile(path)),
);
for (let i = 0; i < results.addTag.length; i++) {
const item = results.addTag[i];
// Insert chunks
if (contents.length) {
for await (const chunk of chunkDocument({
filepath: item.path,
contents: contents[i],
maxChunkSize: this.maxChunkSize,
digest: item.cacheKey,
})) {
handleChunk(chunk);
}
}
for (const item of results.addTag) {
await db.run(
`
INSERT INTO chunk_tags (chunkId, tag)
SELECT id, ? FROM chunks
WHERE cacheKey = ? AND path = ?
`,
[tagString, item.cacheKey, item.path],
);
markComplete([item], IndexResultType.AddTag);
accumulatedProgress += 1 / results.addTag.length / 4;
yield {
progress: accumulatedProgress,
desc: `Chunking ${getBasename(item.path)}`,
desc: `Adding ${getBasename(item.path)}`,
status: "indexing",
};
}