Repository navigation
[6.x] Fix the Stache watcher not removing entries whose files were deleted - #15797
Open
DanielDarrenJones wants to merge 5 commits into
Open
DanielDarrenJones wants to merge 5 commits into
DanielDarrenJones wants to merge 5 commits into
Conversation
These fail on 6.x: a file deleted on disk is never removed from the Stache, and a renamed file keeps pointing at its old path for the rest of the request.
Since statamic#11863 the watcher's list of deleted files holds keys, but the loop that flushes them still looked each one up as a path, so nothing was removed. Deleted paths are now kept with their keys, and the decision is made after the modified files are read: a key that comes back under a new path was renamed, so only its old path is released; any other key is flushed. The memoized paths are also dropped once the path index is updated, so added and renamed files are found for the rest of the request. Fixes statamic#12824
A term file holds the term and its localizations, so several keys share one path. Flipping paths() kept only one key per path, leaving the other localizations cached.
This branch has not been deployed
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.
Fixes #12824.
When the Stache watcher is on and an entry's file is deleted from disk, the entry is never removed:
Entry::find()still returns it, it still appears in queries and the Control Panel, and onlyphp please stache:cleargets rid of it. Since #11863,handleFileChanges()builds its list of deleted files as keys, but the loop that flushes them still treats each value as a path (getKeyFromPath($path)), finds nothing and removes nothing.The same method also kept the paths it memoized before applying any changes, so for the rest of that request a renamed file still pointed at its old path, and a newly added file couldn't be found by
getItem().What this changes
handleDeletedItem().Tests
Each of these fails on
6.xand passes with this change:6.xBasicStoreTest::the_watcher_removes_an_item_whose_file_was_deletedBasicStoreTest::the_watcher_keeps_an_item_whose_file_was_renamedBasicStoreTest::the_watcher_handles_a_deleted_and_an_added_file_in_the_same_requestStores\EntriesStoreTest::the_watcher_removes_an_entry_whose_file_was_deletedThe tests are in their own commit, so you can see them fail before the fix:
The full suite passes with the change.