node_node_access() seems to make nodes completely uncacheable

Created on 12 January 2018, almost 7 years ago
Updated 3 July 2023, over 1 year ago

Here's a funny thing I ran into:

  1. node_node_access() is called for update and delete (among others) on any node page that has local actions
  2. The way both operations are handled in said function, the user cache context is always added except when the user has the update any $type content or delete any $type content permission
  3. By default, DynamicPageCacheSubscriber::shouldCacheResponse() marks any page with the session or user cache contexts as UNCACHEABLE because those two are the defaults in the service container's renderer.config.auto_placeholder_conditions.contexts parameter

I ran into this when I wrote my own cache context with a user. prefix (e.g.: user.is_subscribed) and noticed that all of my nodes kept folding into the user context.

The fix is easy: Stop having node_node_access() cache almost any result by user. Instead, only vary by user when the user actually has the $operation own $type content permission.

Marked as major because, if I'm right about this, currently not a single node is being cached on standard Drupal 8 installs. Which would seem really odd to me because I can hardly imagine that being the case. So please prove me wrong. Although my local testing proves the fix actually stops my node pages from folding into the user cache context.

πŸ› Bug report
Status

Closed: duplicate

Version

9.5

Component
Node systemΒ  β†’

Last updated about 3 hours ago

No maintainer
Created by

πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024