perf: make CommitAdmin SHA search index-friendly - #1967
Merged
Conversation
`commitid__iexact` compiles to `UPPER(commitid) = UPPER(...)`, which no btree index can serve, so admin SHA search sequentially scanned ~172M rows. Match on exact lowercase equality instead, and accept `<repoid> <full SHA>` so the search can use the commits_repoid_commitid unique index. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
🤖 Harness AI Code Review in progress… · View results → |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1967 +/- ##
=======================================
Coverage 91.61% 91.61%
=======================================
Files 1336 1336
Lines 53174 53177 +3
Branches 1647 1647
=======================================
+ Hits 48715 48718 +3
Misses 4138 4138
Partials 321 321
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
calvin-codecov
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Searching the admin commits changelist by full SHA (e.g.
?q=cdd4a06d…) was taking a very long time against the ~172M rowcommitstable.The filter used
commitid__iexact, which Django compiles toUPPER(commitid) = UPPER(...). Wrapping the column in a function means no btree index can serve the predicate, so Postgres fell back to a sequential scan — even though the same lookup written asWHERE commitid = '…'in psql is fast.Changes to
CommitAdmin.get_search_results:commitid=term.lower()) instead of__iexact. SHAs are hex and stored lowercase elsewhere in the app (GraphQL commit search already doessearch.lower()), so case-insensitive matching bought nothing and cost the index.<repoid> <full SHA>term, which filters on both columns and lets the query use the existingcommits_repoid_commitidunique index. This is the fastest path and is now called out insearch_help_text.No schema change. SHA-only search is now planned like the equivalent raw query; a standalone
commitidindex would be a separate follow-up if SHA-only lookups need to be fast without a repoid.Test plan
ruff format/ruff checkclean on both changed filespytest core/tests/test_admin.py -k CommitAdmin(needs the docker Postgres; couldn't reachpostgreshost locally)<repoid> <full SHA>and confirm the result loads quicklyMade with Cursor