From daaf61f40c395731183aab860e2c1ec0a928ad19 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Fri, 4 May 2007 05:25:49 +0000 Subject: [PATCH] merged fix for MDL-9617, performance issues in calendar --- calendar/lib.php | 28 +++++----------------------- lib/datalib.php | 4 +++- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index d0b223fd4f..8cfbbfb724 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -1236,30 +1236,12 @@ function calendar_get_default_courses($ignoreref = false) { } } - // find all course this student can view - if ($allcourses = get_my_courses($USER->id, 'visible DESC, sortorder ASC', '*', true)) { - foreach ($allcourses as $courseid => $acourse) { - if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) { - continue; - } - // let's try to see if there is any direct assignments on this context - // one can have multiple assignments - // just use anyone that has something, or else use empty string - // i am not even sure enrolment type is needed here, seems like only the array keys are needed - // just keeping this code for safety - if ($roleassign = get_records_sql("SELECT * FROM {$CFG->prefix}role_assignments - WHERE contextid = $context->id - AND userid = $USER->id")) { - foreach ($roleassign as $rid => $rs) { - if (!empty($rs->enrol)) { - $courses[$courseid] = $rs->enrol; - break; - } - } - } - } + if (isset($CFG->adminseesall)) { + return get_my_courses($USER->id, 'visible DESC', '*', $CFG->adminseesall); + } + else { + return get_my_courses($USER->id, 'visible DESC', '*', false); } - return $courses; } function calendar_preferences_button() { diff --git a/lib/datalib.php b/lib/datalib.php index 534d9472a2..90bd0c7bc0 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -820,7 +820,9 @@ ORDER BY $sort"); } } - if (!empty($USER->id) && ($USER->id == $userid)) { + // MDL-9671, my courses should only get cached when '*' is chosen as the field, otherwise courses + // can not be displayed properly as cached courses might contain missing course name etc + if (!empty($USER->id) && ($USER->id == $userid) && $fields=='*') { $USER->mycourses[$doanything] = $mycourses; } -- 2.39.5