Skip to content
Browse files

MDL-32340 Improve performance of calendar selection

  • Loading branch information...
1 parent e16e230 commit d083084a236ca94f4237ad39d82e4481ac378016 @andrewnicols andrewnicols committed May 9, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 calendar/lib.php
View
11 calendar/lib.php
@@ -1508,15 +1508,16 @@ function calendar_get_default_courses() {
}
$courses = array();
- if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
+ if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', context_system::instance())) {
list ($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
- $sql = "SELECT DISTINCT c.* $select
+ $sql = "SELECT c.* $select
FROM {course} c
- JOIN {event} e ON e.courseid = c.id
- $join";
+ $join
+ WHERE EXISTS (SELECT 1 FROM {event} e WHERE e.courseid = c.id)
+ ";
$courses = $DB->get_records_sql($sql, null, 0, 20);
foreach ($courses as $course) {
- context_instance_preload($course);
+ context_helper::preload_from_record($course);
}
return $courses;
}

0 comments on commit d083084

Please sign in to comment.
Something went wrong with that request. Please try again.