]> git.mjollnir.org Git - moodle.git/commitdiff
A little bit of caching for get_my_courses, related to MDL-8149
authormoodler <moodler>
Mon, 22 Jan 2007 03:24:27 +0000 (03:24 +0000)
committermoodler <moodler>
Mon, 22 Jan 2007 03:24:27 +0000 (03:24 +0000)
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
lib/datalib.php

index f5bf96eb8144b51c2f0a0dc87e27b23daac6084b..bdf14a078525b6d2ed028825a554a67b5e608985 100755 (executable)
@@ -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') {
index 7235624c6818c9046258503bae31043bf06f21fb..2c89ac1b8af637a3fc9bfd40231720f155e0ad2e 100644 (file)
@@ -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