lib/accesslib.php 讓訪客權限的查詢,改用 cache。
[root@dywang html]# diff -urN moodle/lib/accesslib.php moodle23/lib/accesslib.php
--- moodle/lib/accesslib.php 2012-08-10 08:05:01.000000000 +0800
+++ moodle23/lib/accesslib.php 2014-02-25 13:28:26.000000000 +0800
@@ -256,7 +256,8 @@
* @return array
*/
function get_role_access($roleid) {
- global $DB, $ACCESSLIB_PRIVATE;
+ global $DB, $ACCESSLIB_PRIVATE,$CFG; //dywang
/* Get it in 1 DB query...
* - relevant role caps at the root and down
@@ -264,6 +265,12 @@
*/
//TODO: MUC - this could be cached in shared memory to speed up first page loading, web crawlers, etc.
+ // Temporary hack for better performance http://tracker.moodle.org/browse/MDL-25288
+ if (6 == $roleid) { // Guest role dywang
+ return unserialize(file_get_contents($CFG->dataroot . '/cache/guest_role_access_cache.serialized'));
+ } else if ('update_guest_role_access' == $roleid) { // For update script
+ $roleid = 6;
+ }
$accessdata = get_empty_accessdata();
@@ -3822,7 +3829,7 @@
if (empty($fields)) {
$fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, '.
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '.
- 'u.country, u.picture, u.idnumber, u.department, u.institution, '.
+ 'u.department, u.country, u.picture, u.idnumber, u.department, u.institution, '. //dywang
'u.lang, u.timezone, u.lastaccess, u.mnethostid, r.name AS rolename, r.sortorder';
}
guest_role_access_cache_update.php 存放在 admin/cli 目錄下。
[root@moodle moodle23]# vim admin/cli/guest_role_access_cache_update.php
<?php
define('CLI_SCRIPT', true);
require_once('../../config.php');
require_once('../../lib/accesslib.php');
$accessInfo = serialize(get_role_access('update_guest_role_access'));
$success = file_put_contents($CFG->dataroot . '/cache/guest_role_access_cache.serialized', $accessInfo);
echo ($success ? "Guest role access file updated! $success bites written.\n" : "ERROR during guest access file update!\n");
?>
[root@moodle moodle23]# crontab -e 29 * * * * php /$moodledir/moodle23/admin/cli/guest_role_access_cache_update.php PHP Warning: require_once(../../config.php): failed to open stream: No such fil e or directory in /var/www/html/moodle23/admin/cli/guest_role_access_cache_updat e.php on line 5
[root@moodle moodle23]# crontab -e 29 * * * * cd /var/www/html/moodle23/admin/cli && /usr/bin/php guest_role_access Guest role access file updated! 1188 bites written.