Skip to content

Commit

Permalink
MDL-77965 calendar: Improve performance of data extract
Browse files Browse the repository at this point in the history
The UNION caused the query to be run in a way that is very
inefficient on MySQL, separating the queries causes each of them to
run in a much more efficient form.

Any duplicated will be filtered out on the PHP side instead of in
the database. On large Moodle sites this is preferable as the
extract is likely to be performed on a server dedicated to running
the Moodle cron and so there will be less of effect on resources
that are used to serve end users.
  • Loading branch information
NeillM committed Feb 23, 2024
1 parent 6de5117 commit fed4c20
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions calendar/classes/privacy/provider.php
Expand Up @@ -118,9 +118,9 @@ public static function get_contexts_for_userid(int $userid) : contextlist {
(e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE e.userid = :cuserid
UNION
SELECT ctx.id
WHERE e.userid = :cuserid";
$contextlist->add_from_sql($sql, $params);
$sql = "SELECT ctx.id
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext
JOIN {modules} m ON m.id = cm.module
Expand Down

0 comments on commit fed4c20

Please sign in to comment.