MDL-65170 core_user: perf improvement for user_get_user_details_courses

We don't always need to iterate over the user's courses, so only fetch
them when we do.
This commit is contained in:
Jake Dallimore
2019-04-08 09:05:40 +08:00
parent 06d2ee0fde
commit 077825f8c9
+2 -3
View File
@@ -597,9 +597,6 @@ function user_get_user_details_courses($user) {
global $USER;
$userdetails = null;
// Get the courses that the user is enrolled in (only active).
$courses = enrol_get_users_courses($user->id, true);
$systemprofile = false;
if (can_view_user_details_cap($user) || ($user->id == $USER->id) || has_coursecontact_role($user->id)) {
$systemprofile = true;
@@ -610,6 +607,8 @@ function user_get_user_details_courses($user) {
$userdetails = user_get_user_details($user, null);
} else {
// Try through course profile.
// Get the courses that the user is enrolled in (only active).
$courses = enrol_get_users_courses($user->id, true);
foreach ($courses as $course) {
if (user_can_view_profile($user, $course)) {
$userdetails = user_get_user_details($user, $course);