feat: improve OwnerAdmin array fields and speed up changelist#1405
Closed
thomasrockhu-codecov wants to merge 1 commit into
Closed
feat: improve OwnerAdmin array fields and speed up changelist#1405thomasrockhu-codecov wants to merge 1 commit into
thomasrockhu-codecov wants to merge 1 commit into
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Contributor
Author
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
Improvements to the Django
OwnerAdmin(codecov_auth/admin.py), split out onto a fresh branch offmain:repository_countcolumn was built with aCount("repository", distinct=True)annotation, which added aLEFT JOIN repos ... GROUP BY owneridto the changelist queryset. Django's paginator then wrapped that inSELECT COUNT(*) FROM (... GROUP BY ownerid) subquery, scanning the fullowners×reposspace 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).Subquery(Coalesced to0) so there is noGROUP BYon the outer query — the paginator count collapses to a plainSELECT COUNT(*) FROM owners, and the per-row repo count only runs for the ~100 displayed rows.show_full_count = Falseto skip even that unfiltered count on the landing view.admins/organizations/permissionowner-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
dbspans, dominated by the paginator count query above.Test plan
pytest codecov_auth/tests/test_admin.py::OwnerAdminTest(addedtest_get_queryset_annotates_repository_count; existing array-field display tests included).SELECT COUNT(*) FROM (... GROUP BY ownerid)query should be gone and p50/p95 should drop toward sub-second.Notes
th/admin-owner-id-array-fields(PR feat: add RBAC (Viewer/Member/Admin) to Django admin #1398); this branch isolates it againstmain.Made with Cursor