Skip to content

feat: improve OwnerAdmin array fields and speed up changelist#1405

Closed
thomasrockhu-codecov wants to merge 1 commit into
mainfrom
th/owner-admin-changelist-perf
Closed

feat: improve OwnerAdmin array fields and speed up changelist#1405
thomasrockhu-codecov wants to merge 1 commit into
mainfrom
th/owner-admin-changelist-perf

Conversation

@thomasrockhu-codecov

Copy link
Copy Markdown
Contributor

Summary

Improvements to the Django OwnerAdmin (codecov_auth/admin.py), split out onto a fresh branch off main:

  • Fixes a severe changelist slowdown. The repository_count column was built with a Count("repository", distinct=True) annotation, which added a LEFT JOIN repos ... GROUP BY ownerid to the changelist queryset. Django's paginator then wrapped that in SELECT COUNT(*) FROM (... GROUP BY ownerid) subquery, scanning the full owners×repos space on every page load. Sentry showed this single query at p50 ≈ 11.6 s / p95 ≈ 14.4 s, accounting for ~77% of all DB time on the page (page p95 ≈ 32 s, p99 ≈ 52 s).
    • Replaced it with a correlated Subquery (Coalesced to 0) so there is no GROUP BY on the outer query — the paginator count collapses to a plain SELECT COUNT(*) FROM owners, and the per-row repo count only runs for the ~100 displayed rows.
    • Set show_full_count = False to skip even that unfiltered count on the landing view.
  • Renders the admins / organizations / permission owner-id array fields as read-only lists of links to the related admin pages, so staff can see who each id refers to and jump straight to them.

Investigation

Root-caused via Sentry (production, codecov/api): the Owner changelist transaction spent ~88% of wall time in db spans, dominated by the paginator count query above.

Test plan

  • pytest codecov_auth/tests/test_admin.py::OwnerAdminTest (added test_get_queryset_annotates_repository_count; existing array-field display tests included).
  • After deploy, re-check the Sentry breakdown for the Owner changelist — the SELECT COUNT(*) FROM (... GROUP BY ownerid) query should be gone and p50/p95 should drop toward sub-second.

Notes

Made with Cursor

Render the admins/organizations/permission owner-id array fields as
read-only lists of links to the related admin pages so staff can see
who each id refers to and jump straight to them.

Replace the joined repository_count annotation with a correlated
Subquery (Coalesced to 0) and set show_full_count = False, so the admin
paginator no longer wraps the changelist in a full owners x repos
COUNT(*) ... GROUP BY ownerid query (~11s p50 in production).

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.89%. Comparing base (701e991) to head (6112e79).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/codecov-api/codecov_auth/admin.py 97.36% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1405   +/-   ##
=======================================
  Coverage   91.89%   91.89%           
=======================================
  Files        1325     1325           
  Lines       50868    50905   +37     
  Branches     1626     1626           
=======================================
+ Hits        46744    46780   +36     
- Misses       3818     3819    +1     
  Partials      306      306           
Flag Coverage Δ
apiunit 94.94% <97.36%> (+<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.

@codecov-notifications

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/codecov-api/codecov_auth/admin.py 97.36% 1 Missing ⚠️

📢 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.

@thomasrockhu-codecov

Copy link
Copy Markdown
Contributor Author

Superseded by the split PRs: #1406 (changelist count-query performance fix) and #1407 (owner-id array-field display). Closing this combined PR in favor of the two focused ones.

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