Permalink
Browse files

MDL-30509 backport perf improvement in role cleanup in cohort sync

This patch simplifies the role cleanup sql, it is not necessary to look for roles without enrolment instance because all roles are automatically unassigned when deleting enrol instances.
  • Loading branch information...
skodak committed Jan 21, 2012
1 parent 269c884 commit 13a1eb3c10f5e4acd0f3d926279be45b7a54d298
Showing with 5 additions and 7 deletions.
  1. +5 −7 enrol/cohort/locallib.php
View
@@ -173,15 +173,13 @@ function enrol_cohort_sync($courseid = NULL) {
}
// remove unwanted roles - include ignored roles and disabled plugins too
- $onecourse = $courseid ? "AND c.instanceid = :courseid" : "";
+ $onecourse = $courseid ? "AND e.courseid = :courseid" : "";
$sql = "SELECT ra.roleid, ra.userid, ra.contextid, ra.itemid
FROM {role_assignments} ra
- JOIN {context} c ON (c.id = ra.contextid AND c.contextlevel = :coursecontext $onecourse)
- LEFT JOIN (SELECT e.id AS enrolid, e.roleid, ue.userid
- FROM {user_enrolments} ue
- JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'cohort')
- ) x ON (x.enrolid = ra.itemid AND ra.component = 'enrol_cohort' AND x.roleid = ra.roleid AND x.userid = ra.userid)
- WHERE x.userid IS NULL AND ra.component = 'enrol_cohort'";
+ JOIN {context} c ON (c.id = ra.contextid AND c.contextlevel = :coursecontext)
+ JOIN {enrol} e ON (e.id = ra.itemid AND e.enrol = 'cohort' $onecourse)
+ LEFT JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = ra.userid)
+ WHERE ra.component = 'enrol_cohort' AND ue.id IS NULL";
$params = array('coursecontext' => CONTEXT_COURSE, 'courseid' => $courseid);
$rs = $DB->get_recordset_sql($sql, $params);

0 comments on commit 13a1eb3

Please sign in to comment.