Clear featured-list caches when featured learning paths are edited - #3757
Draft
mbertrand wants to merge 8 commits into
Draft
Clear featured-list caches when featured learning paths are edited#3757mbertrand wants to merge 8 commits into
mbertrand wants to merge 8 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tion Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The browser query client's 30-minute staleTime (matched to the CDN TTL) means the editor's own session never refetches the featured list after they edit a learning path — the backend purge only helps on a full page reload. Invalidate the featured query key in the mutations that map to the backend's cache-clearing write hooks so the editor sees their change immediately on client-side navigation too. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Hoist the tasks import to module level (tasks was already imported at module scope, so the function-local import bought nothing), shrink the bulk-action id set (featured_list_id__in coerces strings), and delete the tautological retry-config test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rize Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
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?
Closes https://github.com/mitodl/hq/issues/11979
Description (What does it do?)
Channel managers couldn't see featured-list edits for up to 24h (Redis view cache) plus 30min (Fastly page cache). Now:
featured_resourcesRedis cache, hard-purges/c/unit/<name>in Fastly, and soft-purges the homepage.call_fastly_purge_apigains asoft=Truekwarg (sendsFastly-Soft-Purge: 1).How can this be tested?
Run the full stack (
COMPOSE_PROFILES=backend,frontend,keycloak,apisix) with the anonymous view cache enabled: setREDIS_VIEW_CACHE_DURATION=600inenv/backend.local.env(the shared default is 0, which disables it) and restart web + celery.Seed featured lists, log in once at http://open.odl.local:8062 as the admin user (
admin@odl.local/admin), then make that user a learning-path editor:In a private/incognito window (anonymous), load a unit channel page — e.g. http://open.odl.local:8062/c/unit/mitx — and note the courses in the featured carousel. Load the homepage too. This primes the anonymous Redis cache for
/api/v1/featured/.In the window where you're logged in as the admin/editor user, go to http://open.odl.local:8062/learningpaths, open "MITx Featured Resources", and remove a course from the list (or add one via a course card's add-to-list dialog). You must be logged in as an admin or learning-path editor — anonymous or regular users can't see or edit learning paths. Watch the worker pick it up:
Within a second or two of the edit you should see:
The Fastly purges are skipped locally (no
FASTLY_API_KEY); on RC/prod they become real PURGE requests against/c/unit/<name>(hard) and/(soft).Reload the incognito channel page and homepage: the featured carousel reflects the edit. Without this PR, the anonymous featured API response stays cached for
REDIS_VIEW_CACHE_DURATION(24h default in deployed envs) and the pages keep rendering the old list.I validated the backend chain locally by driving the same endpoints from the API side (editor DELETE on a featured list item → 204 → celery task ran in 9ms → anonymous
/api/v1/featured/fresh within seconds, where it stayed stale before). The React Query invalidation is covered by the jest tests (yarn test frontends/api/src/hooks/learningPaths frontends/api/src/hooks/learningResources).Additional Context
?topic=...) stay cached up to s-maxage (30 min). The base URL the editor refreshes is hard-purged. Per-channel surrogate keys are the upgrade path if that ever matters.