MDL-62384 mod_lesson: Move WHERE clause to JOIN
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 10 May 2018 08:38:07 +0000 (16:38 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 11 May 2018 01:15:29 +0000 (09:15 +0800)
mod/lesson/classes/privacy/provider.php

index a2b0706..afb6417 100644 (file)
@@ -133,19 +133,24 @@ class provider implements
                AND ctx.contextlevel = :modulelevel
          LEFT JOIN {lesson_attempts} la
                 ON la.lessonid = l.id
+               AND la.userid = :userid1
          LEFT JOIN {lesson_branch} lb
                 ON lb.lessonid = l.id
+               AND lb.userid = :userid2
          LEFT JOIN {lesson_grades} lg
                 ON lg.lessonid = l.id
+               AND lg.userid = :userid3
          LEFT JOIN {lesson_overrides} lo
                 ON lo.lessonid = l.id
+               AND lo.userid = :userid4
          LEFT JOIN {lesson_timer} lt
                 ON lt.lessonid = l.id
-             WHERE la.userid = :userid1
-                OR lb.userid = :userid2
-                OR lg.userid = :userid3
-                OR lt.userid = :userid4
-                OR lo.userid = :userid5";
+               AND lt.userid = :userid5
+             WHERE la.id IS NOT NULL
+                OR lb.id IS NOT NULL
+                OR lg.id IS NOT NULL
+                OR lo.id IS NOT NULL
+                OR lt.id IS NOT NULL";
 
         $params = [
             'lesson' => 'lesson',