Problem/Motivation
When a page containing a view of grantable nodes is cached for anonymous viewing, updating the grants of the nodes involved doesn't invalidate the cached page. This causes the page to use a stale version, not reflecting the actual state of the nodes. This prompts a cache clear when one is not needed.
Related to and an expansion of https://www.drupal.org/project/nodeaccess/issues/2962423
Steps to reproduce
Setup work:
1. Ensure render caching is enabled and functional - this is important because this bug doesn't happen if this is disabled.
2. Create a content type and configure it to use nodeaccess.
3. Create a view with a block display that lists down the nodes of the content type in Step 1. Ensure Tag-based caching is enabled.
4. Place this block on an empty page (e.g. homepage without anything else) - important, you do not want other things affecting the reproduction.
Actual debugging:
1. Create a node of the content type in the previous section. Grant access to authenticated users.
2. View the page with the view block from the previous section.
3. In a separate browser/browser profile, while logged out, view the homepage. - this is important, Drupal will cache this version of the page for anonymous users.
4. Edit the node in Step 1, grant access to anonymous users.
5. Repeat steps 2 and 3.
Expected:
- In step 4, nodeaccess should have invalidated all the needed cache tags.
- In step 5, the node would be rendered in the view for both authenticated an anonymous users.
Actual:
- In step 4, nodeaccess only invalidated the "node:{id}" tag.
- In step 5, the node would only be rendered in the view for authenticated users. For anonymous users, the cached version in step 3 is used.
The cached content in step 3 was not invalidated because it does not yet have "node:{id}" that step 4 is invalidating. The cache metadata in step 3 is only aware of the view and its tags, not the tags of the soon-to-be-granted nodes.
Proposed resolution
Invalidate more tags:
- node_list
- node_list:{bundle}
- 4xx-response
This follows the behavior of EntityBase::getListCacheTagsToInvalidate() which is called when saving a node. For reference, publishing/unpublishing the nodes correctly invalidates the cache and renders an updated page.
Remaining tasks
- Test
- Review
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | nodeaccess-clear_node_list_and_4xx-3354058.patch | 784 bytes | fskreuz |
Issue fork nodeaccess-3354058
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
fskreuz commentedComment #3
d.fisher commentedLet's move this into a branch and MR against 2.0.x
Comment #5
d.fisher commentedPipelines pass and merge request looks good. If we can get a review confirming this resolves the issue with no additional side effects we can move this to RTBC.