Skip to content

Commit

Permalink
MDL-64216 privacy: Split query to use indexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
micaherne committed Dec 4, 2018
1 parent 2cea0bd commit 11361ac
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions grade/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,32 @@ public static function get_contexts_for_userid(int $userid) : \core_privacy\loca
JOIN {context} ctx
ON ctx.instanceid = gi.courseid
AND ctx.contextlevel = :courselevel
LEFT JOIN {grade_grades} gg
JOIN {grade_grades} gg
ON gg.itemid = gi.id
AND (gg.userid = :userid1 OR gg.usermodified = :userid2)
LEFT JOIN {grade_grades_history} ggh
WHERE gg.userid = :userid1 OR gg.usermodified = :userid2";
$params = [
'courselevel' => CONTEXT_COURSE,
'userid1' => $userid,
'userid2' => $userid
];
$contextlist->add_from_sql($sql, $params);

$sql = "
SELECT DISTINCT ctx.id
FROM {grade_items} gi
JOIN {context} ctx
ON ctx.instanceid = gi.courseid
AND ctx.contextlevel = :courselevel
JOIN {grade_grades_history} ggh
ON ggh.itemid = gi.id
AND (
ggh.userid = :userid3
OR ggh.loggeduser = :userid4
OR ggh.usermodified = :userid5
)
WHERE gg.id IS NOT NULL
OR ggh.id IS NOT NULL";
WHERE ggh.userid = :userid1
OR ggh.loggeduser = :userid2
OR ggh.usermodified = :userid3";
$params = [
'courselevel' => CONTEXT_COURSE,
'userid1' => $userid,
'userid2' => $userid,
'userid3' => $userid,
'userid4' => $userid,
'userid5' => $userid,
'userid3' => $userid
];
$contextlist->add_from_sql($sql, $params);

Expand Down

0 comments on commit 11361ac

Please sign in to comment.