From 30db947c777b8ccbeb9c6a331fcaae97d9ce8f8c Mon Sep 17 00:00:00 2001 From: Rob Leidle Date: Mon, 5 Aug 2024 16:39:12 -0700 Subject: [PATCH] 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 --- core/indexing/chunk/ChunkCodebaseIndex.ts | 29 ++++++++--------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index d3e4e9a0d..eba76ad8b 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -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", }; }