MDL-34864 improve enrol_category sync performance
This commit is contained in:
@@ -265,6 +265,7 @@ function enrol_category_sync_full() {
|
||||
|
||||
// first of all add necessary enrol instances to all courses
|
||||
$parentcat = $DB->sql_concat("cat.path", "'/%'");
|
||||
$parentcctx = $DB->sql_concat("cctx.path", "'/%'");
|
||||
// need whole course records to be used by add_instance(), use inner view (ci) to
|
||||
// get distinct records only.
|
||||
// TODO: Moodle 2.1. Improve enrol API to accept courseid / courserec
|
||||
@@ -293,12 +294,11 @@ function enrol_category_sync_full() {
|
||||
$sql = "SELECT e.*
|
||||
FROM {enrol} e
|
||||
JOIN {context} ctx ON (ctx.instanceid = e.courseid AND ctx.contextlevel = :courselevel)
|
||||
LEFT JOIN (SELECT DISTINCT cctx.path
|
||||
FROM {course_categories} cc
|
||||
LEFT JOIN ({course_categories} cc
|
||||
JOIN {context} cctx ON (cctx.instanceid = cc.id AND cctx.contextlevel = :catlevel)
|
||||
JOIN {role_assignments} ra ON (ra.contextid = cctx.id AND ra.roleid $roleids)
|
||||
) cat ON (ctx.path LIKE $parentcat)
|
||||
WHERE e.enrol = 'category' AND cat.path IS NULL";
|
||||
) ON (ctx.path LIKE $parentcctx)
|
||||
WHERE e.enrol = 'category' AND cc.id IS NULL";
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $instance) {
|
||||
@@ -333,12 +333,11 @@ function enrol_category_sync_full() {
|
||||
FROM {enrol} e
|
||||
JOIN {context} ctx ON (ctx.instanceid = e.courseid AND ctx.contextlevel = :courselevel)
|
||||
JOIN {user_enrolments} ue ON (ue.enrolid = e.id)
|
||||
LEFT JOIN (SELECT DISTINCT cctx.path, ra.userid
|
||||
FROM {course_categories} cc
|
||||
LEFT JOIN ({course_categories} cc
|
||||
JOIN {context} cctx ON (cctx.instanceid = cc.id AND cctx.contextlevel = :catlevel)
|
||||
JOIN {role_assignments} ra ON (ra.contextid = cctx.id AND ra.roleid $roleids)
|
||||
) cat ON (ctx.path LIKE $parentcat AND cat.userid = ue.userid)
|
||||
WHERE e.enrol = 'category' AND cat.userid IS NULL";
|
||||
) ON (ctx.path LIKE $parentcctx AND ra.userid = ue.userid)
|
||||
WHERE e.enrol = 'category' AND cc.id IS NULL";
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $instance) {
|
||||
$userid = $instance->userid;
|
||||
|
||||
Reference in New Issue
Block a user