MDL-72704 message: Additional optimisation tweaks

* Return early if the `userids` params is empty or if the filtered
user IDs end up being empty.
This commit is contained in:
Jun Pataleta 2025-04-11 11:08:36 +08:00
parent 7e2931d7d3
commit 9cd200777e
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7

View File

@ -3396,6 +3396,11 @@ class core_message_external extends external_api {
throw new moodle_exception('You do not have permission to perform this action.');
}
// Return early if no userids are provided.
if (empty($params['userids'])) {
return [];
}
// Filter the user IDs, removing the IDs of the users that the current user cannot view.
require_once($CFG->dirroot . '/user/lib.php');
$userfieldsapi = \core_user\fields::for_userpic()->including('username', 'deleted');
@ -3406,9 +3411,14 @@ class core_message_external extends external_api {
return user_can_view_profile($targetuser);
});
// Return early if no user IDs are left after filtering.
if (empty($filteredids)) {
return [];
}
return \core_message\helper::get_member_info(
$params['referenceuserid'],
$filteredids ?? [],
$filteredids,
$params['includecontactrequests'],
$params['includeprivacyinfo']
);