MDL-45678 assignsubmission_comments: Improve performance for permissions checking

This commit is contained in:
Damien Bezborodov
2014-07-04 14:25:06 +09:30
parent fc415ee908
commit 0ba5f02b15
5 changed files with 31 additions and 9 deletions
+18 -1
View File
@@ -7460,11 +7460,21 @@ function extract_suspended_users($context, &$users, $ignoreusers=array()) {
* or enrolment has expired or not started.
*
* @param context $context context in which user enrolment is checked.
* @param bool $context Enable or disable (default) the request cache
* @return array list of suspended user id's.
*/
function get_suspended_userids($context){
function get_suspended_userids(context $context, $usecache = false) {
global $DB;
// Check the cache first for performance reasons if enabled.
if ($usecache) {
$cache = cache::make('core', 'get_suspended_userids');
$susers = $cache->get($context->id);
if ($susers !== false) {
return $susers;
}
}
// Get all enrolled users.
list($sql, $params) = get_enrolled_sql($context);
$users = $DB->get_records_sql($sql, $params);
@@ -7481,5 +7491,12 @@ function get_suspended_userids($context){
}
}
}
// Cache results for the remainder of this request.
if ($usecache) {
$cache->set($context->id, $susers);
}
// Return.
return $susers;
}