From: martinlanghoff Date: Mon, 19 Mar 2007 06:33:45 +0000 (+0000) Subject: Auto-linking filters: fix serious caching bug in forum mailouts X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9aa9080756186f8a8a62936d5b0aaf0440b62d2e;p=moodle.git Auto-linking filters: fix serious caching bug in forum mailouts Autolinking of glossaries, activity, resources and wiki names were using a trivial single-entry cache implemented with static vars. The cache was _not_ keyed on course. This bug was visible during forum_cron() which walks many courses. The cache would get "stuck" on the first course that had something to put in the cache. All mailouts from there onwards would autolink to stuff in the wrong course. --- diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php index 8ab80466b5..992f3809bf 100644 --- a/filter/activitynames/filter.php +++ b/filter/activitynames/filter.php @@ -8,12 +8,20 @@ global $CFG; + // Trivial-cache - keyed on $cachedcourseid static $activitylist; + static $cachedcourse; if (empty($courseid)) { $courseid = SITEID; } + // Initialise/invalidate our trivial cache if dealing with a different course + if (!isset($cachedcourseid) || $cachedcourseid !== (int)$courseid) { + $activitylist = array(); + } + $cachedcourseid = (int)$courseid; + /// It may be cached if (empty($activitylist)) { diff --git a/mod/glossary/filter.php b/mod/glossary/filter.php index a96013b75e..3a8b8a9eb2 100644 --- a/mod/glossary/filter.php +++ b/mod/glossary/filter.php @@ -3,17 +3,26 @@ function glossary_filter($courseid, $text) { global $CFG; + // Trivial-cache - keyed on $cachedcourseid static $nothingtodo; static $conceptlist; - - if (!empty($nothingtodo)) { // We've been here in this page already - return $text; - } + static $cachedcourseid; if (empty($courseid)) { $courseid = SITEID; } + // Initialise/invalidate our trivial cache if dealing with a different course + if (!isset($cachedcourseid) || $cachedcourseid !== (int)$courseid) { + $conceptlist = array(); + $nothingtodo = false; + } + $cachedcourseid = (int)$courseid; + + if ($nothingtodo === true) { + return $text; + } + /// Create a list of all the concepts to search for. It may be cached already. if (empty($conceptlist)) { diff --git a/mod/resource/filter.php b/mod/resource/filter.php index 8f28f9b5ac..f6080ef906 100644 --- a/mod/resource/filter.php +++ b/mod/resource/filter.php @@ -7,15 +7,24 @@ global $CFG; + // Trivial-cache - keyed on $cachedcourseid static $nothingtodo; static $resourcelist; + static $cachedcourseid; - if (!empty($nothingtodo)) { // We've been here in this page already + // if we don't have a courseid, we can't run the query, so + if (empty($courseid)) { return $text; } - // if we don't have a courseid, we can't run the query, so - if (empty($courseid)) { + // Initialise/invalidate our trivial cache if dealing with a different course + if (!isset($cachedcourseid) || $cachedcourseid !== (int)$courseid) { + $resourcelist = array(); + $nothingtodo = false; + } + $cachedcourseid = (int)$courseid; + + if ($nothingtodo === true) { return $text; } diff --git a/mod/wiki/filter.php b/mod/wiki/filter.php index 554a888c75..d116790a64 100755 --- a/mod/wiki/filter.php +++ b/mod/wiki/filter.php @@ -10,17 +10,26 @@ global $CFG; + // Trivial-cache - keyed on $cachedcourseid static $nothingtodo; static $wikipagelist; - - if (!empty($nothingtodo)) { // We've been here in this page already - return $text; - } + static $cachedcourseid; if (empty($courseid)) { $courseid = SITEID; } + // Initialise/invalidate our trivial cache if dealing with a different course + if (!isset($cachedcourseid) || $cachedcourseid !== (int)$courseid) { + $wikipagelist = array(); + $nothingtodo = false; + } + $cachedcourseid = (int)$courseid; + + if (!empty($nothingtodo)) { // We've been here in this page already + return $text; + } + /// Create a list of all the wikis to search for. It may be cached already. if (empty($wikipagelist)) {