Skip to content

Commit

Permalink
MDL-30509 backport perf improvement in role cleanup in cohort sync
Browse files Browse the repository at this point in the history
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 13a1eb3
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions enrol/cohort/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 13a1eb3

Please sign in to comment.