Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In the function message_subscribe_get_subscribers, the user load function is used multiple times when checking access permissions for all the subscribed users.
This has come up as a performance issue on a high traffic site with thousands of users subscribed to single items.
The function should be using user_load_multiple as per the Drupal api page:
https://api.drupal.org/api/drupal/modules!user!user.module/function/user...
This function should be used whenever you need to load more than one user from the database.
Comments
Comment #1
T-loComment #2
T-loComment #3
amitaibuThanks. Please remove trailing spaces from the Patch. Also another minor comment:
$users => $accounts
Last thing - next time if I can please open this in GitHub, as it's easier to review there, thanks :)
Comment #5
maikeru CreditAttribution: maikeru commentedFYI: I think this fails because it needs array_keys in the call to user_load_multiple
Comment #6
T-lo@maikeru, you're right, I realised that while porting to the current full release branch..
I'll get this re written later this week.
Comment #7
maikeru CreditAttribution: maikeru commentedI've gone ahead and added array_keys in there, since I needed to create a patch for our deployment process.
Comment #9
maikeru CreditAttribution: maikeru commentedAnd, fix the undef $uid
Comment #10
amitaibuThanks, minor comment:
$users => $accounts
Comment #11
T-lothanks @maikeru
@amitaibu I've switched it to $accounts
Comment #12
darrenwh CreditAttribution: darrenwh commentedHi,
No need to create the variable $account, just do this on line 263/261
if (!entity_access('view', $entity_type, $entity, $accounts[$uid])) {
Apart from that all good.
Darren
Comment #13
T-loHi Darren,
The $account variable was already there, we're just changing how it's populated.
Is creating a variable that's only used once a problem? Perhaps you could create another issue if so
Comment #14
darrenwh CreditAttribution: darrenwh commentedAll looks good
Comment #15
RoySegall CreditAttribution: RoySegall commentedI'll try to a look on that one.
Comment #16
DamienMcKennaA minor update per @T-lo's suggestion.
Comment #17
T-loComment #19
amitaibuMerged, thanks.