Repository navigation
Remove deleted rules from caches on full refresh - #6876
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
A full cache refresh did not remove everything that was deleted from the database, so deleted Shields rules kept applying until the app restarted: 1. `PageRuleCache` and `HostnameRuleCache` are ETS bags keyed by domain. The refresh inserted the current rules of each site and then deleted only the keys that were no longer present. A site that still had any rule kept its key, and a deleted rule stayed in the bag next to the remaining ones. 2. `merge_items([], _)` returned early, before stale keys were deleted. When the last row of a table was removed (for example the only IP rule on a small instance), the full refresh found no rows and left the old entries in the cache. `Plausible.Cache.Adapter.delete_stale/2` now cleans up after a merge. For regular tables it removes the keys that are no longer present, as before. For bag tables it compares individual objects and removes the ones that are not among the refreshed items. The new objects are inserted first, so readers never observe a site without its rules during a refresh. The empty-list shortcut is gone: an empty result of a full refresh now empties the cache, while `delete_stale_items?: false` (used by the recently-updated refresh) still keeps existing entries. This also makes the dummy-site workaround in the gate keeper test unnecessary.
|
|
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.
Changes
Fixes #6858
A full cache refresh did not remove everything that was deleted from the database, so deleted Shields rules kept applying until the app restarted:
PageRuleCacheandHostnameRuleCacheare ETS bags keyed by domain. The refresh inserted each site's current rules and then deleted only the keys that were no longer present. A site that still had any rule kept its key, and a deleted rule stayed in the bag next to the remaining ones.merge_items([], _)returned early, before stale keys were deleted. When the last row of a table was removed (for example the only IP rule on a small instance), the full refresh found no rows and kept the old entries.What changed:
Plausible.Cache.Adapter.delete_stale/2, used bymerge_items/2. For regular tables it removes the keys that are no longer present, as before. For bag tables it compares individual objects and removes the ones that are not among the refreshed items. New objects are inserted first, so readers never see a site without its rules during a refresh.merge_items/2is removed. An empty result of a full refresh now empties the cache.delete_stale_items?: false(used by the "recently updated" refresh) still leaves existing entries alone.delete_stale_items?: falsefor the old one. The dummy site in the gate keeper test, added as a workaround for this limitation, is no longer needed and is removed.Plausible.CacheTest, and for removed page, hostname and IP rules in their cache tests.Tests
Changelog
Documentation
Dark mode