]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13334 get_role_access() static cache in cron only; merged from MOODLE_19_STABLE
authorskodak <skodak>
Tue, 5 Feb 2008 10:41:05 +0000 (10:41 +0000)
committerskodak <skodak>
Tue, 5 Feb 2008 10:41:05 +0000 (10:41 +0000)
lib/accesslib.php

index fd4f9394fa4852cc903cfa525b5845fd06326841..03bbbf0796da02b785712f7b358c191aa4abe3ab 100755 (executable)
@@ -216,8 +216,6 @@ function get_role_access($roleid, $accessdata=NULL) {
         $accessdata['loaded'] = array();
     }
 
-    $base = '/' . SYSCONTEXTID;
-
     //
     // Overrides for the role IN ANY CONTEXTS
     // down to COURSE - not below -
@@ -230,13 +228,35 @@ function get_role_access($roleid, $accessdata=NULL) {
             WHERE rc.roleid = {$roleid}
                   AND ctx.contextlevel <= ".CONTEXT_COURSE."
             ORDER BY ctx.depth, ctx.path";
-    if ($rs = get_recordset_sql($sql)) {
-        while ($rd = rs_fetch_next_record($rs)) {
+
+    // we need extra caching in cron only
+    if (defined('FULLME') and FULLME === 'cron') {
+        static $cron_cache = array();
+
+        if (!isset($cron_cache[$roleid])) {
+            $cron_cache[$roleid] = array();
+            if ($rs = get_recordset_sql($sql)) {
+                while ($rd = rs_fetch_next_record($rs)) {
+                    $cron_cache[$roleid][] = $rd;
+                }
+                rs_close($rs);
+            }
+        }
+
+        foreach ($cron_cache[$roleid] as $rd) {
             $k = "{$rd->path}:{$roleid}";
             $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
         }
-        unset($rd);
-        rs_close($rs);
+        
+    } else {
+        if ($rs = get_recordset_sql($sql)) {
+            while ($rd = rs_fetch_next_record($rs)) {
+                $k = "{$rd->path}:{$roleid}";
+                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
+            }
+            unset($rd);
+            rs_close($rs);
+        }
     }
 
     return $accessdata;