Fix Zoekt filter order to avoid performance regression
Summary
Reorder filters in CodeQueryBuilder so scoping filters (repo_ids, traversal_ids) come immediately after query_string, before meta filters like archived.
Problem
Placing meta filters between query_string and scoping filters causes Zoekt to scan metadata across all repositories before narrowing down, adding ~1-1.4 seconds of latency.
See investigation details in #586416 (comment 3011961678)
Changes
- Reordered filters in
build_payloadmethod:-
Before:
query_string → archived → repo_ids/traversal_ids → access_branches -
After:
query_string → repo_ids/traversal_ids → archived → access_branches
-
Before:
- Updated JSON fixtures to match new filter order
- Added specs to verify filter ordering is maintained
Expected Performance Improvements
| Search Type | Before | After |
|---|---|---|
| Project searches | ~1.8s | ~200ms |
| Group searches | ~1.7s | ~600ms |
How to Test
- Run the specs:
bundle exec rspec ee/spec/lib/search/zoekt/code_query_builder_spec.rb - All 15 tests should pass, including the new filter ordering tests
Closes #586416 (closed)