Skip to content

Optimize: Cache navigation bar queries (TASK-20260202)#3

Open
whlongg wants to merge 1 commit intomasterfrom
fix/TASK-20260202
Open

Optimize: Cache navigation bar queries (TASK-20260202)#3
whlongg wants to merge 1 commit intomasterfrom
fix/TASK-20260202

Conversation

@whlongg
Copy link
Owner

@whlongg whlongg commented Feb 4, 2026

Automated fix for TASK-20260202. Moved from master commit e8d0f79.

- Added judge/utils/caching.py with get_cached_navbar and get_cached_nav_tab.
- Updated judge/template_context.py to use cached functions.
- Added signal handlers in judge/signals.py to invalidate cache on NavigationBar changes.
- Added judge/tests/test_navbar_cache.py for regression testing.
@whlongg
Copy link
Owner Author

whlongg commented Feb 10, 2026

@codex

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8d0f79b90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +73 to +74
cache.delete(NAVBAR_CACHE_KEY)
bump_nav_tab_version()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Defer navbar cache invalidation until updates are committed

Invalidating navbar_tree directly in the post_save/post_delete signal can cache an inconsistent tree: NavigationBarAdmin.changelist_view saves items with disable_mptt_updates() and only rebuilds tree fields afterward (judge/admin/interface.py), so a concurrent request can repopulate navbar_tree from pre-rebuild rows and keep that stale hierarchy for the full TTL. Triggering invalidation on commit (or after the rebuild path completes) avoids persisting an inconsistent navbar.

Useful? React with 👍 / 👎.

Comment on lines +22 to +25
version = cache.get(NAV_TAB_VERSION_KEY)
if version is None:
version = 1
cache.set(NAV_TAB_VERSION_KEY, version + 1, NAV_TAB_CACHE_TTL)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Increment nav-tab cache version atomically

bump_nav_tab_version() does a get then set, which is not atomic under concurrent updates. If two NavigationBar saves/deletes run at the same time, both can read the same old version and write the same incremented value, so only one logical invalidation happens; a request between those writes can cache nav-tab data that remains stale after the second update because the version did not advance again.

Useful? React with 👍 / 👎.

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