From 2af55137891846717acf4c3ac2dd5c9aa2c5f647 Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Fri, 3 Nov 2006 17:29:15 +0000 Subject: [PATCH] MDL-7346 Changed enablerecordcache to be a limit for the size of cache, not just an on/off switch. --- admin/settings/server.php | 2 +- lang/en_utf8/admin.php | 2 +- lib/dmllib.php | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/admin/settings/server.php b/admin/settings/server.php index b01eabaa95..a634dc4fa0 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -177,7 +177,7 @@ $ADMIN->add('server', new admin_externalpage('phpinfo', get_string('phpinfo'), " // "performance" settingpage $temp = new admin_settingpage('performance', get_string('performance', 'admin')); -$temp->add(new admin_setting_configcheckbox('enablerecordcache', get_string('enablerecordcache', 'admin'), get_string('configenablerecordcache', 'admin'), 1)); +$temp->add(new admin_setting_configtext('enablerecordcache', get_string('enablerecordcache', 'admin'), get_string('configenablerecordcache', 'admin'), 50)); $ADMIN->add('server', $temp); if (file_exists("$CFG->dirroot/$CFG->admin/mysql/frame.php")) { diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 76a8c3a0f0..cf4cd00ea9 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -75,7 +75,7 @@ $string['configeditorfontlist'] = 'Select the fonts that should appear in the ed $string['configenableajax'] = 'This setting allows you to control the use of AJAX (advanced client/server interfaces using Javascript) across the whole site. With this setting enabled users can sill make a choice in their profile, otherwise AJAX is disabled for everybody.'; $string['configenablecourserequests'] = 'This will allow any user to request a course be created.'; $string['configenableglobalsearch'] = 'This setting enables global text searching in resources and activities, it is not compatible with PHP 4.'; -$string['configenablerecordcache'] = 'If you enable this, some in-memory caching will be performed while retrieving info from database. This means that your database throughput will be better but, on the other hand, your web server memory requirements will be slightly increased. Generally we recommend this to be enabled unless your server is low on memory. Some processes may choose to override this setting where the developer is certain of a performance increase.'; +$string['configenablerecordcache'] = 'If you set this to a number higher than 0, some in-memory caching will be performed while retrieving info from the database. This means that your database throughput will be better but, on the other hand, your web server memory requirements will be slightly increased. Generally we recommend values of around 50 unless your server is low on memory. Some processes may choose to override this setting where the developer is certain of a performance increase.'; $string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site. To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.'; $string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.'; $string['configenablestats'] = 'If you choose \'yes\' here, Moodle\'s cronjob will process the logs and gather some statistics. Depending on the amount of traffic on your site, this can take awhile. If you enable this, you will be able to see some interesting graphs and statistics about each of your courses, or on a sitewide basis.'; diff --git a/lib/dmllib.php b/lib/dmllib.php index e95d236edc..84ce6a1126 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -40,6 +40,7 @@ $empty_rs_cache = array(); // Keeps copies of the recordsets used in one invocation $metadata_cache = array(); // Keeps copies of the MetaColumns() for each table used in one invocations $record_cache = array(); // Keeps copies of all simple get_record results from one invocation +$record_cache_size = 0; // Count of get_record results stored in this invocation /// FUNCTIONS FOR DATABASE HANDLING //////////////////////////////// @@ -371,7 +372,7 @@ function count_records_sql($sql) { */ function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') { - global $CFG, $record_cache; + global $CFG, $record_cache, $record_cache_count; // Check to see whether this record is eligible for caching (fields=*, only condition is id) $docache = false; @@ -388,8 +389,12 @@ function get_record($table, $field1, $value1, $field2='', $value2='', $field3='' $record = get_record_sql('SELECT '.$fields.' FROM '. $CFG->prefix . $table .' '. $select); // If we're caching records, store this one (supposing we got something - we don't cache failures) - if (!empty($CFG->enablerecordcache) && $record && $docache) { + if ($record && $docache && $record_cache_count<$CFG->enablerecordcache) { $record_cache[$table][$value1] = $record; + // We only cache records up to a limit. This is to prevent memory usage becoming + // unreasonably high for pages which do things like, load every student record in + // a course, or some such. + $record_cache_count++; } return $record; @@ -2020,4 +2025,4 @@ function db_update_lobs ($table, $sqlcondition, &$clobs, &$blobs) { return $status; } -?> +?> \ No newline at end of file -- 2.39.5