Skip to content

perf: make CommitAdmin SHA search index-friendly - #1967

Merged
thomasrockhu-codecov merged 1 commit into
mainfrom
th/commit-admin-search-exact
Aug 13, 2026
Merged

perf: make CommitAdmin SHA search index-friendly#1967
thomasrockhu-codecov merged 1 commit into
mainfrom
th/commit-admin-search-exact

Conversation

@thomasrockhu-codecov

Copy link
Copy Markdown
Contributor

Summary

Searching the admin commits changelist by full SHA (e.g. ?q=cdd4a06d…) was taking a very long time against the ~172M row commits table.

The filter used commitid__iexact, which Django compiles to UPPER(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 as WHERE commitid = '…' in psql is fast.

Changes to CommitAdmin.get_search_results:

  • Match SHAs with exact lowercase equality (commitid=term.lower()) instead of __iexact. SHAs are hex and stored lowercase elsewhere in the app (GraphQL commit search already does search.lower()), so case-insensitive matching bought nothing and cost the index.
  • Accept a combined <repoid> <full SHA> term, which filters on both columns and lets the query use the existing commits_repoid_commitid unique index. This is the fastest path and is now called out in search_help_text.
  • Bare repoid and bare SHA searches still work as before.

No schema change. SHA-only search is now planned like the equivalent raw query; a standalone commitid index would be a separate follow-up if SHA-only lookups need to be fast without a repoid.

Test plan

  • ruff format / ruff check clean on both changed files
  • pytest core/tests/test_admin.py -k CommitAdmin (needs the docker Postgres; couldn't reach postgres host locally)
  • In admin, search <repoid> <full SHA> and confirm the result loads quickly
  • In admin, search a bare full SHA and confirm it returns the same commit
  • In admin, search a bare repoid and confirm the changelist is unchanged

Made with Cursor

`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>
@thomasrockhu-codecov

Copy link
Copy Markdown
Contributor Author

🤖 Harness AI Code Review in progress… · View results →

@codecov-notifications

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.61%. Comparing base (68c86d1) to head (bf63ec2).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
apiunit 93.94% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@thomasrockhu-codecov
thomasrockhu-codecov added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit 37cd618 Aug 13, 2026
37 checks passed
@thomasrockhu-codecov
thomasrockhu-codecov deleted the th/commit-admin-search-exact branch August 13, 2026 19:44
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.

2 participants