Skip to content

perf: fix blocking bcrypt, defer heavy columns, add API key index#40

Open
finish06 wants to merge 1 commit into
mainfrom
feature/performance-optimization
Open

perf: fix blocking bcrypt, defer heavy columns, add API key index#40
finish06 wants to merge 1 commit into
mainfrom
feature/performance-optimization

Conversation

@finish06
Copy link
Copy Markdown
Owner

Summary

  • Blocking bcrypt fixverify_password() now runs in thread pool (run_in_executor) in both login handlers, preventing event loop blocking on every auth request
  • Deferred heavy columnsraw_content and file_list excluded from list queries via SQLAlchemy defer(), reducing memory from MB to KB per dashboard/API list request
  • API key index — Added composite index (is_active, key_prefix) on api_keys table for fast prefix-based lookups

Changes

File Change
app/routes/auth.py run_in_executor for bcrypt in browser login
app/api/endpoints/auth.py run_in_executor for bcrypt in API login
app/routes/dashboard.py defer(raw_content, file_list) on sync table query
app/api/endpoints/sync_logs.py defer(raw_content, file_list) on list query
app/models/sync_log.py Composite index on api_keys(is_active, key_prefix)

Expected Impact

Optimization Before After
Login concurrency Serialized (bcrypt blocks event loop) Concurrent (thread pool)
Dashboard memory (500 logs) ~500MB (with raw_content) ~5MB (summary only)
API key lookup Full table scan on fallback Index scan on (is_active, prefix)

Test plan

  • All 950 tests pass
  • mypy type check passes
  • ruff lint + format clean
  • Detail endpoint still returns full raw_content (AC-011, AC-014)

🤖 Generated with Claude Code

- Offload bcrypt verify_password to thread pool (run_in_executor) in both
  login handlers — prevents event loop blocking on every auth request
- Defer raw_content and file_list columns on list queries (dashboard sync
  table + API list endpoint) — reduces memory from MB to KB per query
- Add composite index on api_keys(is_active, key_prefix) for fast lookups

Spec: specs/performance-optimization.md
AC: AC-001, AC-002, AC-010, AC-012, AC-013, AC-020

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant