From 133d5a97dbf57c404e7ecd4f328eef1d961563fb Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 5 Feb 2008 10:41:05 +0000 Subject: [PATCH] MDL-13334 get_role_access() static cache in cron only; merged from MOODLE_19_STABLE --- lib/accesslib.php | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index fd4f9394fa..03bbbf0796 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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; -- 2.39.5