mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
fomrat_string() tuning - memory, speed and accuracy in cron
This commit is contained in:
parent
3c8dd686e0
commit
38701b6910
1 changed files with 12 additions and 7 deletions
|
@ -1410,25 +1410,30 @@ function format_title($string, $plaintext=true, $courseid=null) {
|
||||||
function format_string ($string, $striplinks = false, $courseid=NULL ) {
|
function format_string ($string, $striplinks = false, $courseid=NULL ) {
|
||||||
|
|
||||||
global $CFG, $COURSE;
|
global $CFG, $COURSE;
|
||||||
|
|
||||||
// First replace all ampersands not followed html entity code
|
|
||||||
$string = preg_replace("/\&(?![a-z0-9]{1,8};)/", "&", $string);
|
|
||||||
|
|
||||||
//We'll use a in-memory cache here to speed up repeated strings
|
//We'll use a in-memory cache here to speed up repeated strings
|
||||||
static $strcache = false;
|
static $strcache = false;
|
||||||
|
|
||||||
if ($strcache === false) {
|
if ($strcache === false or count($strcache) > 2000 ) { // this number might need some tuning to limit memory usage in cron
|
||||||
$strcache = array();
|
$strcache = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//init course id
|
||||||
|
if ($courseid === NULL) {
|
||||||
|
$courseid = $COURSE->id;
|
||||||
|
}
|
||||||
|
|
||||||
//Calculate md5
|
//Calculate md5
|
||||||
$md5 = md5($string.'<+>'.$striplinks.'<+>'.$courseid);
|
$md5 = md5($string.'<+>'.$striplinks.'<+>'.$courseid.'<+>'.current_language());
|
||||||
|
|
||||||
//Fetch from cache if possible
|
//Fetch from cache if possible
|
||||||
if(isset($strcache[$md5])) {
|
if (isset($strcache[$md5])) {
|
||||||
return $strcache[$md5];
|
return $strcache[$md5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First replace all ampersands not followed html entity code
|
||||||
|
$string = preg_replace("/\&(?![a-z0-9]{1,8};)/", "&", $string);
|
||||||
|
|
||||||
if (!empty($CFG->filterall)) {
|
if (!empty($CFG->filterall)) {
|
||||||
$string = filter_text($string, $courseid);
|
$string = filter_text($string, $courseid);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue