Skip to content

Commit a929935

Browse files
committed
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
1 parent b7140e8 commit a929935

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/services/code-index/worker-utils/scanner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ export class Scanner {
327327
const files: string[] = []
328328
let processedCount = 0
329329

330+
// Create ignore instance once, outside the loop
331+
const ig = ignore().add(allExcludePatterns)
332+
330333
for (const pattern of allIncludePatterns) {
331334
const matches = await glob(pattern, {
332335
cwd: this.workspacePath,
@@ -339,7 +342,6 @@ export class Scanner {
339342
for (const file of matches) {
340343
// Double-check exclusion patterns using ignore
341344
const relativePath = path.relative(this.workspacePath, file)
342-
const ig = ignore().add(allExcludePatterns)
343345
const isExcluded = relativePath ? ig.ignores(relativePath) : false
344346

345347
if (!isExcluded && !files.includes(file)) {

src/workers/indexing-worker.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ignore from "ignore"
1010
import * as fs from "fs/promises"
1111
import * as path from "path"
1212
import { v5 as uuidv5 } from "uuid"
13+
import { createHash } from "crypto"
1314

1415
// Import embedders and vector store directly
1516
import { OpenAiEmbedder } from "../services/code-index/embedders/openai"
@@ -32,7 +33,6 @@ class IndexingWorker {
3233
private fileWatcher: FileWatcher | null = null
3334
private embedder: any = null
3435
private vectorStore: any = null
35-
private ignoreInstance: any = null
3636
private rooIgnoreController: RooIgnoreController | null = null
3737

3838
constructor() {
@@ -55,6 +55,11 @@ class IndexingWorker {
5555

5656
case "start":
5757
await this.startIndexing()
58+
this.sendResponse(id, {
59+
type: "status",
60+
state: "Indexed",
61+
message: "Indexing completed successfully",
62+
})
5863
break
5964

6065
case "stop":
@@ -141,17 +146,6 @@ class IndexingWorker {
141146
// Initialize vector store
142147
this.vectorStore = this.createVectorStore(config)
143148

144-
// Load .gitignore
145-
this.ignoreInstance = ignore()
146-
const ignorePath = path.join(config.workspacePath, ".gitignore")
147-
try {
148-
const content = await fs.readFile(ignorePath, "utf8")
149-
this.ignoreInstance.add(content)
150-
this.ignoreInstance.add(".gitignore")
151-
} catch (error) {
152-
// Ignore error if .gitignore doesn't exist
153-
}
154-
155149
// Initialize RooIgnoreController
156150
this.rooIgnoreController = new RooIgnoreController(config.workspacePath)
157151
await this.rooIgnoreController.initialize()
@@ -277,7 +271,6 @@ class IndexingWorker {
277271
const content = await fs.readFile(filePath, "utf8")
278272

279273
// Calculate hash
280-
const { createHash } = await import("crypto")
281274
const fileHash = createHash("sha256").update(content).digest("hex")
282275

283276
// Check cache

0 commit comments

Comments
 (0)