Skip to content

[MEDIUM] Large database queries without pagination #109

@Tsukieomie

Description

@Tsukieomie

Performance Issue: Unpaginated Database Queries

Severity: MEDIUM
Location: src/main/lib/trpc/routers/files.ts:222-253

Description

File scanning reads entire directory tree without pagination, potentially causing memory spikes on large projects.

Risk

  • Large projects (node_modules, .git) could cause memory issues
  • No timeout on directory traversal
  • Simple 5-second TTL cache may not be sufficient

Current Mitigation

  • Traversal depth limit: 15 (good ✓)
  • File type filtering (good ✓)
  • Basic caching (needs improvement)

Recommendation

1. Add Pagination

interface FileListOptions {
  limit?: number
  offset?: number
  maxFiles?: number  // Hard limit
}

// Stop after maxFiles reached
if (results.length >= maxFiles) break

2. Add Timeout/Cancellation

const abortController = new AbortController()
const timeout = setTimeout(() => abortController.abort(), 5000)

// Check abort signal during traversal
if (abortController.signal.aborted) break

3. Improve Caching Strategy

  • LRU cache with size limit
  • Invalidate on file system changes (use chokidar)
  • Per-directory caching instead of full tree

4. Stream Results

// Instead of returning all at once
for await (const file of walkDirectory()) {
  yield file  // Stream to client
}

Impact

Medium - Affects performance on large codebases, could cause app to freeze.

Labels: performance, database

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions