Cut down on repeated APISIX user DB changes and logins - #3378
Merged
Conversation
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates APISIX user middleware to reduce unnecessary database writes when repeated requests provide unchanged APISIX identity data, while preserving synchronization when user or profile fields change.
Changes:
- Adds helper functions to map and compare APISIX user/profile fields before saving.
- Replaces unconditional user/profile updates with conditional saves and profile syncs.
- Adds tests for ambiguous identity handling and changed/unchanged identity behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
main/middleware/apisix_user.py |
Adds conditional user/profile synchronization and skips repeated login for already-authenticated matching users. |
main/middleware/apisix_user_test.py |
Adds regression coverage for ambiguous matches, skipped writes, and changed user/profile fields. |
mbertrand
force-pushed
the
mb/apisix_midware_db
branch
from
June 1, 2026 18:52
f7074c0 to
d56e361
Compare
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.
What are the relevant tickets?
Related: mitodl/hq#11506
Description (What does it do?)
Updates ApisixUserMiddleware so requests avoid unnecessary User/Profile saves or logins when APISIX-provided identity data has not changed.
This keeps APISIX/Keycloak/Django identity data synchronized by still comparing the APISIX-controlled user and profile fields on each request, while only saving the User, syncing the Profile, or calling login() when the current request actually requires it.
How can this be tested?
last_login, Userupdated_on, and Profileupdated_at. Refresh the app and visit several authenticated and user-aware pages, such as search/results, a resource detail page, dashboard/profile, and a saved/favorites flow. Re-check those timestamps and confirm they do not change just from browsing with unchanged APISIX identity data.