Skip to content

[6.x] Forget the structure's memoized collection on collection save and delete - #15549

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix/collection-structure-collection-memo
Sep 30, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix/collection-structure-collection-memo

Conversation

@joshdaugherty

Copy link
Copy Markdown
Contributor

Fixes #15548.

CollectionStructure::collection() caches the collection in Blink under collection-structure-collection-{handle}. Collection::save() clears collection-{handle}* by prefix, which doesn't match that key, and Collection::delete() doesn't clear it at all. So after a collection is replaced by a new instance with different sites, its structure keeps answering from the old instance, and structure()->in($site) returns null for a site the collection is now in.

This adds a Blink::forget() for that key to both save() and delete().

Tests:

  • saving_clears_the_collection_memoized_by_its_structure saves a structured collection on en, resolves its structure, saves a new instance on fr, and asserts the structure resolves a tree for fr. It fails without the fix.
  • deleting_clears_the_collection_memoized_by_its_structure asserts the key is gone after delete(). It fails without the fix.
  • it_saves_the_collection_through_the_api mocks Blink strictly, so it now expects the extra forget().

Other ways to fix this, in case one of them is preferred:

  • Rename the cache key to collection-{handle}-structure-collection, so the existing flushStartingWith() in save() covers it. That's cleaner, but delete() would still need an explicit clear.
  • Stop caching the collection on the structure, and call Collection::findByHandle() each time. This runs once per entry, so it trades the cache for repeated repository lookups.

This is separate from #5046, which is about Tree's cached data and isn't changed here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016o2kMZ4DZaNGJ4pUqPov7D
@jasonvarga
jasonvarga merged commit cd35d09 into statamic:6.x Sep 30, 2026
62 checks passed
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.

Collection::save() doesn't clear the collection cached by CollectionStructure

2 participants