From 8e82745aeddeade05bb857d54972e7b0190c1266 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 22 Jan 2007 03:24:27 +0000 Subject: [PATCH] A little bit of caching for get_my_courses, related to MDL-8149 Resetting it in load_all_capabilities() means it gets flushed everytime role_assign() or role_unassign() is called on the current user, which should be enough. The cache is not reset when others assign/unassign roles, but Moodle has always had this problem. --- lib/accesslib.php | 2 ++ lib/datalib.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/accesslib.php b/lib/accesslib.php index f5bf96eb81..bdf14a0785 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1035,6 +1035,8 @@ function load_all_capabilities() { return; } + unset($USER->mycourses); // Reset a cache used by get_my_courses + load_user_capability(); // Load basic capabilities assigned to this user if ($USER->username == 'guest') { diff --git a/lib/datalib.php b/lib/datalib.php index 7235624c68..2c89ac1b8a 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -683,6 +683,14 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c */ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields='*', $doanything=false,$limit=0) { + global $USER; + + if (!empty($USER->id) && ($USER->id == $userid)) { + if (!empty($USER->mycourses)) { + return $USER->mycourses; // Just return the cached version + } + } + $mycourses = array(); // Fix fields to refer to the course table c -- 2.39.5