Skip to content

Commit

Permalink
MDL-63564 core_question: Avoid using UNION in get_users_in_context()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed Nov 2, 2018
1 parent 6cd2de3 commit 0762883
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions question/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,18 @@ public static function get_users_in_context(userlist $userlist) {

// A user may have created or updated a question.
// Questions are linked against a question category, which has a contextid field.
$sql = "SELECT q.createdby AS userid
$sql = "SELECT q.createdby, q.modifiedby
FROM {question} q
JOIN {question_categories} cat ON cat.id = q.category
WHERE cat.contextid = :contextid
UNION
SELECT q.modifiedby AS userid
FROM {question} q
JOIN {question_categories} cat ON cat.id = q.category
WHERE cat.contextid = :contextidagain";
JOIN {question_categories} cat
ON cat.id = q.category
WHERE cat.contextid = :contextid";

$params = [
'contextid' => $context->id,
'contextidagain' => $context->id,
'contextid' => $context->id
];

$userlist->add_from_sql('userid', $sql, $params);
$userlist->add_from_sql('createdby', $sql, $params);
$userlist->add_from_sql('modifiedby', $sql, $params);
}

/**
Expand Down

0 comments on commit 0762883

Please sign in to comment.