Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-45678 assignsubmission_comments: Improve performance for permissi…

…ons checking
  • Loading branch information...
commit 0ba5f02b15f467700de0c9407c3cd0cd65692b1c 1 parent fc415ee
@dbezborodovrp dbezborodovrp authored
View
1  lang/en/cache.php
@@ -46,6 +46,7 @@
$string['cachedef_databasemeta'] = 'Database meta information';
$string['cachedef_eventinvalidation'] = 'Event invalidation';
$string['cachedef_externalbadges'] = 'External badges for particular user';
+$string['cachedef_get_suspended_userids'] = 'List of suspended user identifiers per course';
$string['cachedef_gradecondition'] = 'User grades cached for evaluating conditional availability';
$string['cachedef_groupdata'] = 'Course group information';
$string['cachedef_htmlpurifier'] = 'HTML Purifier - cleaned content';
View
19 lib/accesslib.php
@@ -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;
}
View
9 lib/db/caches.php
@@ -221,5 +221,12 @@
'mode' => cache_store::MODE_SESSION,
'simplekeys' => true,
'simpledata' => true
- )
+ ),
+
+ // For the function get_suspended_userids() in core_access.
+ 'get_suspended_userids' => array(
+ 'mode' => cache_store::MODE_REQUEST,
+ 'simplekeys' => true,
+ 'simpledata' => true,
+ ),
);
View
3  lib/enrollib.php
@@ -1406,6 +1406,9 @@ public function update_user_enrol(stdClass $instance, $userid, $status = NULL, $
$DB->update_record('user_enrolments', $ue);
context_course::instance($instance->courseid)->mark_dirty(); // reset enrol caches
+ // Invalidate core_access cache for get_suspended_userids.
+ cache_helper::invalidate_by_definition('core', 'get_suspended_userids', array(), array($instance->courseid));
+
// Trigger event.
$event = \core\event\user_enrolment_updated::create(
array(
View
8 mod/assign/locallib.php
@@ -132,9 +132,6 @@ class assign {
/** @var bool whether to exclude users with inactive enrolment */
private $showonlyactiveenrol = null;
- /** @var array list of suspended user IDs in form of ([id1] => id1) */
- public $susers = null;
-
/** @var array cached list of participants for this assignment. The cache key will be group, showactive and the context id */
private $participants = array();
@@ -6958,10 +6955,7 @@ public function show_only_active_users() {
* @return bool true is user is active in course.
*/
public function is_active_user($userid) {
- if (is_null($this->susers) && !is_null($this->context)) {
- $this->susers = get_suspended_userids($this->context);
- }
- return !in_array($userid, $this->susers);
+ return !in_array($userid, get_suspended_userids($this->context, true));
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.