Problem/Motivation
Found via #3539161: Static cache access policy checking.
Because access policy checks make permission checking slightly more expensive, we can save approx 1ms from 80-100ms requests by checking for hook_node_grants() implementations prior to checking permissions. This follows the same pattern as several other places that early return when there's no grants, including the cache context cacheable metata method.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Screenshot from 2026-04-10 11-13-47.png | 315.26 KB | catch |
| #4 | Screenshot from 2026-04-10 11-13-54.png | 304.27 KB | catch |
Issue fork drupal-3584098
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:
- 3584098-early-return-in
changes, plain diff MR !15414
Comments
Comment #3
catchComment #4
catchAdding before/after xhprof (the first screenshot is the 'after'...)
Comment #5
smustgrave commentedTest failure seems related to this change
Comment #6
catchI think we need to rework the test here - it's using state to manipulate whether grants are returned or not for a user, which makes the module implements check unreliable.
Also can't see why it's a functional test - it makes no http requests, could probably go all the way to a unit test.
Comment #7
catchUpdated the test assertion. The difference is that when no module implements node grants, users without admin access now get 'all' instead of 'view.all' for the cache context. This is more consistent with how the node access handler/storage itself handles that case.
Also added a note to #3414655: [META] Convert Functional tests classes which make no HTTP requests into Kernel tests for refactoring the test to a kernel or unit test.
Comment #8
smustgrave commentedLGTM
Comment #11
amateescu commentedCommitted and pushed 527ecd06d5e to main and 74761ea199b to 11.x. Thanks!