Optimize stale todo resolution performance
Goal
Optimize for high-scale deployments. Add database index and performance monitoring.
Related to #20637 (closed)
Can be done in parallel with or after Phase 1d
Implementation Details
1. Database Index Migration
Location: db/migrate/XXXXXX_add_index_for_stale_todos.rb
Add partial index for query optimization:
- Columns:
[:target_type, :target_id, :state, :action] - WHERE clause:
state = 'pending' AND target_type = 'MergeRequest' - Use
add_concurrent_indexfor zero-downtime
2. Performance Instrumentation
Add logging for large batch resolutions and Prometheus metrics.
Test Coverage Required
-
Migration tests -
Performance benchmarks (100+ todos) -
Verify index is used in query plans
Files to Create
-
db/migrate/XXXXXX_add_index_for_stale_todos.rb -
spec/migrations/XXXXXX_add_index_for_stale_todos_spec.rb -
Update app/services/todo_service.rbwith instrumentation
Acceptance Criteria
-
Index created successfully -
Migration uses concurrent index -
Query performance improves -
Database review approved
Expected Improvements
- Query time: 50-100ms → <10ms
- Consistent performance regardless of table size
Estimated Effort: 2-3 days