User Role Update hook calls node_access_needs_rebuild unnecessarily

Created on 25 August 2023, about 1 year ago
Updated 30 August 2023, about 1 year ago

Problem/Motivation

When ever any change is made to a User Role, even simply renaming the Role, the update hook is called and the a node access rebuild flag is set. Node access rebuild is an incredibly time consuming process for large websites with thousands of node.


The node access table only needs rebuilding if permissions have changed, and only the permissions that this module uses.

Steps to reproduce

Edit a Role and change it's name, not even changing a permission.
You will now have the warning message to rebuild all of the node access permissions even though no permissions have changed.

Proposed resolution

Only call node_access_needs_rebuild(TRUE); if a permission has changed in a role that will effect any of the filters that this module adds.


I have patched the views_node_access_filter_user_role_update(EntityInterface $entity) method to only call the rebuild function if a role has either gained or lost one of the following permissions:

  • 'edit any [TYPE] content'
  • 'edit own [TYPE] content'
  • 'revert [TYPE] revisions'

This should reduce the amount of times that the node access table is flagged to rebuild.

I'm not sure if that is the correct set of permissions to monitor?

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom altcom_neil

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

Comments & Activities

Production build 0.71.5 2024