Issue #3630504: Read the masquerade data of a user once per request

  • RoleManager::getData() reads all msqrole data of a user with one query and keeps it for the rest of the request (keyed by user ID), instead of one query per call. The current user proxy calls it on every role and permission check, hundreds of times per page.
  • setData() and removeData() drop what is kept for that user, so a change made in the same request is read fresh.
  • A call with a NULL user ID keeps its current behaviour.

Testing: the module has no tests. On a Drupal 11.4 site with msqrole 1.0.21, a page of a logged-in user made 10 instead of about 220 database queries (dynamic page cache hit) and loaded about twice as fast. Masquerading as a role and switching back still work (checked with the site's end-to-end test of that form). The commit also applies to 1.0.21.

Issue: https://www.drupal.org/i/3630504

Text generated with AI

Merge request reports

Loading
Loading