Updating grants does not invalidate cached pages with views of that node when viewing anonymously

Created on 13 April 2023, about 1 year ago

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

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fskreuz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024