[FIX][UI]: Display CRUD changes on Users and Teams pages without full reload#3157
Closed
crivetimihai wants to merge 1 commit intomainfrom
Closed
[FIX][UI]: Display CRUD changes on Users and Teams pages without full reload#3157crivetimihai wants to merge 1 commit intomainfrom
crivetimihai wants to merge 1 commit intomainfrom
Conversation
4 tasks
3455955 to
3cc3749
Compare
- Add Cache-Control: no-cache headers to teams and users endpoints - Update admin.js to handle cache-busting properly - Fix ESLint issues in admin.js - Update users_partial.html template - Add cache invalidation tests Closes #2691 Signed-off-by: Marek Dano <mk.dano@gmail.com>
3cc3749 to
3b2e358
Compare
Collaborator
|
The description mentions |
Collaborator
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.
🐛 Bug-fix PR
📌 Summary
Fixes stale UI data on Teams and Users admin pages when running multiple gateway replicas behind nginx. The root cause was three layers of caching preventing CRUD changes from being reflected:
auth_cachepublished invalidation messages tomcpgw:auth:invalidatebutCacheInvalidationSubscriberonly listened onmcpgw:cache:invalidate, so other replicas never cleared their in-memory auth caches.HX-Triggerheaders, so the frontend never knew to refresh the listsproxy_cache_valid 200 5sand add_headerCache-Control "private, max-age=5"always caused stale responses for all /admin GET requests. Since nginx overrides backend Cache-Control headers, this was solved client-side with_t=Date.now()cache-busting query parameters._t=Date.now()timestamp cache-busting in admin.js already bypasses both nginx proxy cache and browser cache🔁 Reproduction Steps
Users Page
Teams Page
🐞 Root Cause
CRUD operations on Users and Teams are cached behind the nginx 5s cache time. So when the operations are executed on the admin UI, the changes are not reflected on the UI. The whole page must be reloaded to see them.
💡 Fix Description
Changes by file
mcpgateway/cache/registry_cache.pyCacheInvalidationSubscriberto bothmcpgw:cache:invalidateandmcpgw:auth:invalidatechannels_listen_loop_process_auth_invalidation()to clear L1 in-memory auth caches (_user_cache, _team_cache, _role_cache, _teams_list_cache, _revocation_cache, _context_cache, _revoked_jtis) across replicasmcpgateway/admin.pyHX-Triggerheader toadmin_create_teamto refresh teams listHX-Triggerheader toadmin_delete_userto refresh users list_tcache-busting timestamp to server-renderedhx-getURLs for members/non-members partials and their infinite scrollnext_page_urlmcpgateway/static/admin.js_t=Date.now()cache-busting to teams partial, users partial, members partial, non-members partial, team edit, user edit, and team members refresh fetchesmcpgateway/templates/admin.html_tcache-busting toloadTeamMembersView(),loadAddMembersView(), andeditTeamSafe()HTMX ajax callsmcpgateway/templates/users_partial.htmlhx-on::config-requestto dynamically append_ton the user edit button'shx-getrequesttests/unit/mcpgateway/cache/test_cache_invalidation_subscriber.pyFakePubSubsubscribe/unsubscribe signatures to accept*channels(matching the new two-channel subscription)tests/js/admin-search.test.jsexpect.stringContaining()to accommodate the_tquery parameter🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)