Skip to content

Commit

Permalink
MDL-34864 improve enrol_category sync performance
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 18, 2012
1 parent 7033316 commit 3d7f23c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions enrol/category/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3d7f23c

Please sign in to comment.