Skip to content

Commit

Permalink
Auto-linking filters: fix serious caching bug in forum mailouts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinlanghoff committed Mar 19, 2007
1 parent 8cf990b commit 9aa9080
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
8 changes: 8 additions & 0 deletions filter/activitynames/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ function activitynames_filter($courseid, $text) {

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)) {
Expand Down
17 changes: 13 additions & 4 deletions mod/glossary/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 12 additions & 3 deletions mod/resource/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ function resource_filter($courseid, $text) {

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;
}

Expand Down
17 changes: 13 additions & 4 deletions mod/wiki/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ function wiki_filter($courseid, $text) {

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)) {
Expand Down

0 comments on commit 9aa9080

Please sign in to comment.