Now format_string() uses an in-memory cache per request to make
things faster. Really noticeable in logs page!
This commit is contained in:
@@ -1065,6 +1065,17 @@ function format_string ($string, $striplinks = false, $courseid=NULL ) {
|
||||
|
||||
global $CFG, $course;
|
||||
|
||||
//We'll use a in-memory cache here to speed up repeated strings
|
||||
static $strcache;
|
||||
|
||||
//Calculate md5
|
||||
$md5 = md5($string.$striplinks);
|
||||
|
||||
//Fetch from cache if possible
|
||||
if(isset($strcache[$md5])) {
|
||||
return $strcache[$md5];
|
||||
}
|
||||
|
||||
if (empty($courseid)) {
|
||||
if (!empty($course->id)) { // An ugly hack for better compatibility
|
||||
$courseid = $course->id; // (copied from format_text)
|
||||
@@ -1079,6 +1090,9 @@ function format_string ($string, $striplinks = false, $courseid=NULL ) {
|
||||
$string = preg_replace('/(<a[^>]+?>)(.+?)(<\/a>)/is','$2',$string);
|
||||
}
|
||||
|
||||
//Store to cache
|
||||
$strcache[$md5] = $string;
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user