Repository navigation
core: prefetch token owners and memberships - #25803
Conversation
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25803 +/- ##
=======================================
Coverage 92.29% 92.29%
=======================================
Files 1185 1185
Lines 79557 79577 +20
Branches 4351 4351
=======================================
+ Hits 73424 73445 +21
+ Misses 6067 6066 -1
Partials 66 66
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
authentik PR Installation instructions Instructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-841c4f240a4bbf4ad033830fec7a06ce63fa25d2
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-841c4f240a4bbf4ad033830fec7a06ce63fa25d2Afterwards, run the upgrade commands from the latest release notes. |
Nothing reads an owner's groups, roles, or computed user fields from the token API, and fetching them cost several queries per token. Use PartialUserSerializer and join the owner, so serializing a page of tokens takes one query. user_obj on tokens, and on token_obj in SCIM sources and SSF providers, now has the PartialUser shape instead of the full User.
Playwright e2eDownload this run's HTML report and traces, then open the report: gh run download 38911247180 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-reportInstallation instructionsInstructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-4a88c8645a378ed09836bd8536d9b21ba7156874
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-4a88c8645a378ed09836bd8536d9b21ba7156874Afterwards, run the upgrade commands from the latest release notes. |
* main: (101 commits) ci: exclude node_modules from Go lint (#26961) website/integrations: ch-ui: document the email_verified requirement (#26978) website/docs: add expression policy for case-insensitive unique usernames (#26974) core: prefetch token owners and memberships (#25803) website/integrations: add detailed explanation for setting GH Org limit (#8604) website/integrations: add opensearch (#26938) endpoints: fix MultipleObjectsReturned (#26971) core, web: update translations (#26963) website/docs: single-logout: add information around proxy providers for single logout (#26563) common/saml: move exceptions and logout request parser to common (#26533) stages/authenticator_webauthn: accept ML-DSA credentials (#26381) crypto: add ML-DSA certificate generation (#26380) website/integrations: add ch-ui (#26935) website/integrations: add kibana (#26936) core: bump pydantic from 2.13.5 to 2.14.0 (#26969) core: bump rust-toolchain from 1.99.0 to 1.99.1 (#26967) core: bump aws-cdk-lib from 2.272.0 to 2.273.0 (#26968) core: bump github.com/prometheus/client_golang from 1.24.1 to 1.25.0 (#26965) core: bump github.com/getsentry/sentry-go from 0.49.0 to 0.50.0 (#26966) web/admin: version banner (#26948) ...
A token list includes details about each token's owner, including their groups and roles. If 1,000 tokens belong to the same person, the endpoint repeatedly asks the database for the same person and their memberships.
This one-line change adds
prefetch_related("user__groups", "user__roles")to the token view's queryset. Django fetches the page's owners, groups, and roles in batches. Tokens with the same owner share that loaded user object for the request.The endpoint still returns the same tokens and owner details. The serializers, permission checks, filtering, and pagination are unchanged. Ordinary users still see their own tokens; users with the appropriate permission can see others' tokens. Expired tokens remain included. The loaded objects are local to the request, so changing a membership is reflected in the next request.
Before and after
Local fixture: 10,000 users, each with a group and role, plus 10,000 tokens sharing one owner and another 10,000 tokens with distinct owners. These are medians of three warmed, paired Django API-client requests against dev PostgreSQL. Each before/after pair uses the same fixture and produces byte-for-byte identical responses. Timing includes rendering, excludes network/browser time, and is specific to this fixture. The page-size limit was temporarily raised to 1,000.
This removes repeated owner and membership reads. Other per-token serialization queries remain, so the endpoint's query count still grows with page size. Benchmark data and the page-size setting were rolled back afterward.
Validation
view_tokenpermission; the benchmark compares complete responses for shared and distinct owners.make gensucceeds with no schema or generated-client changes.Made with GPT 6 Astra in Codex, which investigated the bottleneck, wrote the change and tests, ran the benchmarks and checks, and drafted this description under maintainer direction.