fix: ensure navigation sidebar serves fresh data after course publish…#38880
Conversation
…openedx#38852) Replace course_version in the sidebar cache key with a block_structure_version derived from BlockStructureModel.data_version. course_version changes eagerly on publish, causing a cache miss before the block structure is rebuilt — poisoning the cache with stale data for 1 hour. block_structure_version only changes after the async rebuild completes, so cache misses only occur when fresh data is available. This is a backport of openedx#38785. (cherry picked from commit 929815f)
|
Thanks for the pull request, @holaontiveros! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a cache-race where the course navigation sidebar could cache and serve stale block structure data for up to 1 hour immediately after a Studio publish. It does so by switching the sidebar cache key from the eagerly-changing course_version to a block_structure_version derived from BlockStructureModel.data_version, which only changes once the async block structure rebuild completes.
Changes:
- Add a
block_structure_versioncache key (writer-owned) backed byBlockStructureModel.data_version. - Update the navigation sidebar cache key to use
block_structure_versioninstead ofcourse_version. - Add a regression test covering the “publish → stale window → rebuild completes → fresh sidebar” scenario.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| openedx/core/djangoapps/content/block_structure/api.py | Adds block_structure_version read/write helpers and updates cache rebuild flow to refresh the version key. |
| lms/djangoapps/course_home_api/outline/views.py | Switches sidebar cache keying to use block_structure_version to avoid caching stale outlines post-publish. |
| lms/djangoapps/course_home_api/outline/tests/test_view.py | Adds regression test to ensure sidebar doesn’t remain stale after rebuild completion. |
Comments suppressed due to low confidence (1)
openedx/core/djangoapps/content/block_structure/api.py:78
clear_course_from_cachedeletes the underlyingBlockStructureModelrow via the store, but it doesn't clear the newblock_structure_version:{course_key}cache entry. Because that version key is cached withtimeout=None, subsequent readers can keep using a now-stale version value even after the block structure has been cleared/deleted, which can prevent navigation sidebar cache keys from shifting away from stale entries.
_update_block_structure_version(course_key)
def clear_course_from_cache(course_key):
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f7f9508
into
openedx:release/ulmo
Important! there's a check regarding code style failing, this seems to be related with some styling choices in later OEX versions.
… (#38852)
Replace course_version in the sidebar cache key with a block_structure_version derived from BlockStructureModel.data_version. course_version changes eagerly on publish, causing a cache miss before the block structure is rebuilt — poisoning the cache with stale data for 1 hour. block_structure_version only changes after the async rebuild completes, so cache misses only occur when fresh data is available.
This is a backport of #38785.
(cherry picked from commit 929815f)
Description
Describe what this pull request changes, and why. Include implications for people using this change.
Design decisions and their rationales should be documented in the repo (docstring / ADR), per
OEP-19, and can be
linked here.
Useful information to include:
"Developer", and "Operator".
changes.
Supporting information
Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.
Testing instructions
Please provide detailed step-by-step instructions for testing this change.
Deadline
"None" if there's no rush, or provide a specific date or event (and reason) if there is one.
Other information
Include anything else that will help reviewers and consumers understand the change.