From a92993504f99130fabebf25c9a31b27fab9da91f Mon Sep 17 00:00:00 2001 From: hannesrudolph Date: Fri, 4 Jul 2025 09:00:17 -0600 Subject: [PATCH] fix: address PR review comments - Add missing response for 'start' command in worker - Move crypto import to top level for better performance - Remove unused .gitignore instance in worker - Move ignore instance creation outside loop in scanner for better performance --- .../code-index/worker-utils/scanner.ts | 4 +++- src/workers/indexing-worker.ts | 19 ++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/services/code-index/worker-utils/scanner.ts b/src/services/code-index/worker-utils/scanner.ts index e14c155016..3f159f93f8 100644 --- a/src/services/code-index/worker-utils/scanner.ts +++ b/src/services/code-index/worker-utils/scanner.ts @@ -327,6 +327,9 @@ export class Scanner { const files: string[] = [] let processedCount = 0 + // Create ignore instance once, outside the loop + const ig = ignore().add(allExcludePatterns) + for (const pattern of allIncludePatterns) { const matches = await glob(pattern, { cwd: this.workspacePath, @@ -339,7 +342,6 @@ export class Scanner { for (const file of matches) { // Double-check exclusion patterns using ignore const relativePath = path.relative(this.workspacePath, file) - const ig = ignore().add(allExcludePatterns) const isExcluded = relativePath ? ig.ignores(relativePath) : false if (!isExcluded && !files.includes(file)) { diff --git a/src/workers/indexing-worker.ts b/src/workers/indexing-worker.ts index 2b31e4d46a..89cc59bba3 100644 --- a/src/workers/indexing-worker.ts +++ b/src/workers/indexing-worker.ts @@ -10,6 +10,7 @@ import ignore from "ignore" import * as fs from "fs/promises" import * as path from "path" import { v5 as uuidv5 } from "uuid" +import { createHash } from "crypto" // Import embedders and vector store directly import { OpenAiEmbedder } from "../services/code-index/embedders/openai" @@ -32,7 +33,6 @@ class IndexingWorker { private fileWatcher: FileWatcher | null = null private embedder: any = null private vectorStore: any = null - private ignoreInstance: any = null private rooIgnoreController: RooIgnoreController | null = null constructor() { @@ -55,6 +55,11 @@ class IndexingWorker { case "start": await this.startIndexing() + this.sendResponse(id, { + type: "status", + state: "Indexed", + message: "Indexing completed successfully", + }) break case "stop": @@ -141,17 +146,6 @@ class IndexingWorker { // Initialize vector store this.vectorStore = this.createVectorStore(config) - // Load .gitignore - this.ignoreInstance = ignore() - const ignorePath = path.join(config.workspacePath, ".gitignore") - try { - const content = await fs.readFile(ignorePath, "utf8") - this.ignoreInstance.add(content) - this.ignoreInstance.add(".gitignore") - } catch (error) { - // Ignore error if .gitignore doesn't exist - } - // Initialize RooIgnoreController this.rooIgnoreController = new RooIgnoreController(config.workspacePath) await this.rooIgnoreController.initialize() @@ -277,7 +271,6 @@ class IndexingWorker { const content = await fs.readFile(filePath, "utf8") // Calculate hash - const { createHash } = await import("crypto") const fileHash = createHash("sha256").update(content).digest("hex") // Check cache