MDL-63564 core_question: Avoid using UNION in get_users_in_context()
authorMihail Geshoski <mihail@moodle.com>
Fri, 2 Nov 2018 06:14:19 +0000 (14:14 +0800)
committerMihail Geshoski <mihail@moodle.com>
Fri, 2 Nov 2018 06:14:19 +0000 (14:14 +0800)
question/classes/privacy/provider.php

index e59f537..ba690f4 100644 (file)
@@ -360,21 +360,18 @@ class provider implements
 
         // 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);
     }
 
     /**