]> git.mjollnir.org Git - moodle.git/commitdiff
Auto-linking filters: fix serious caching bug in forum mailouts
authormartinlanghoff <martinlanghoff>
Mon, 19 Mar 2007 06:33:45 +0000 (06:33 +0000)
committermartinlanghoff <martinlanghoff>
Mon, 19 Mar 2007 06:33:45 +0000 (06:33 +0000)
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.

filter/activitynames/filter.php
mod/glossary/filter.php
mod/resource/filter.php
mod/wiki/filter.php

index 8ab80466b513edfe88b616e4edcf6ba033057ced..992f3809bfd77c0e26838cfaae006179b4175bdc 100644 (file)
@@ -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)) {
index a96013b75ec115b3c0eeb796d013a170ddd5578f..3a8b8a9eb2d19a702efc4df41ee7a4bfe4fb3989 100644 (file)
@@ -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)) {
index 8f28f9b5ac289a7870df802c70b526cc5bfbe684..f6080ef9067cf639cd3804f003ed38f818d6966b 100644 (file)
@@ -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;
         }
         
index 554a888c7541dc60e490553512b8c84082eda728..d116790a6439a4a5cedee92482f2612a6883530f 100755 (executable)
 
         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)) {