From cd05eba738326dd8b030eea79dfba9c9dddbdc79 Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Thu, 9 Aug 2018 10:28:21 +0100 Subject: [PATCH] MDL-63103 filebrowser: Speed up finding activities with files Before this change the query examined at every course_module record in the context table. With this change we use the course_modules table to more efficiently find all the activities in the course, which means that many less records in the context table need to be examined. --- lib/filebrowser/file_info_context_course.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/filebrowser/file_info_context_course.php b/lib/filebrowser/file_info_context_course.php index 4c8b7977075..c766acaccda 100644 --- a/lib/filebrowser/file_info_context_course.php +++ b/lib/filebrowser/file_info_context_course.php @@ -528,16 +528,15 @@ class file_info_context_course extends file_info { $params1 = ['contextid' => $this->context->id, 'emptyfilename' => '.', 'contextlevel' => CONTEXT_MODULE, - 'depth' => $this->context->depth + 1, - 'pathmask' => $this->context->path . '/%']; + 'course' => $this->course->id]; $sql1 = "SELECT ctx.id AS contextid, f.component, f.filearea, f.itemid, ctx.instanceid AS cmid, " . context_helper::get_preload_record_columns_sql('ctx') . " FROM {files} f INNER JOIN {context} ctx ON ctx.id = f.contextid + INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid WHERE f.filename <> :emptyfilename - AND ctx.contextlevel = :contextlevel - AND ctx.depth = :depth - AND " . $DB->sql_like('ctx.path', ':pathmask') . " "; + AND cm.course = :course + AND ctx.contextlevel = :contextlevel"; $sql3 = ' GROUP BY ctx.id, f.component, f.filearea, f.itemid, ctx.instanceid, ctx.path, ctx.depth, ctx.contextlevel ORDER BY ctx.id, f.component, f.filearea, f.itemid';