mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
calendar: performance optimisations + behaviour fix (MDL-7416 MDL-9617)
With 2500 courses the calendar was causing around 15000 queries at login and 5000 on the home page. - Replaced queries inside loops with single unlooped queries. - Fixed calendar so that course events will show when the users role is assigned at a category level. - Moved calendar_session_vars() function call out of calendar/lib.php (including a lib should not have side effects) Author: Matt Clarkson - with some conflict resolution from MartinL
This commit is contained in:
parent
f261e052f2
commit
37d87d11f9
8 changed files with 39 additions and 16 deletions
|
@ -20,6 +20,8 @@ class block_calendar_month extends block_base {
|
||||||
if ($this->content !== NULL) {
|
if ($this->content !== NULL) {
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
|
|
||||||
$this->content = new stdClass;
|
$this->content = new stdClass;
|
||||||
$this->content->text = '';
|
$this->content->text = '';
|
||||||
|
|
|
@ -16,7 +16,8 @@ class block_calendar_upcoming extends block_base {
|
||||||
if ($this->content !== NULL) {
|
if ($this->content !== NULL) {
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
$this->content = new stdClass;
|
$this->content = new stdClass;
|
||||||
$this->content->text = '';
|
$this->content->text = '';
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,9 @@
|
||||||
|
|
||||||
$strcalendar = get_string('calendar', 'calendar');
|
$strcalendar = get_string('calendar', 'calendar');
|
||||||
|
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
|
|
||||||
$now = usergetdate(time());
|
$now = usergetdate(time());
|
||||||
$nav = calendar_get_link_tag($strcalendar, CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']);
|
$nav = calendar_get_link_tag($strcalendar, CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']);
|
||||||
$day = intval($now['mday']);
|
$day = intval($now['mday']);
|
||||||
|
|
|
@ -17,6 +17,9 @@ if(!$site = get_site()) {
|
||||||
redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
|
redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
|
|
||||||
$pagetitle = get_string('export', 'calendar');
|
$pagetitle = get_string('export', 'calendar');
|
||||||
$now = usergetdate(time());
|
$now = usergetdate(time());
|
||||||
$nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']).' -> '.$pagetitle;
|
$nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']).' -> '.$pagetitle;
|
||||||
|
|
|
@ -64,8 +64,7 @@ define ('CALENDAR_TF_12', '%I:%M %p');
|
||||||
|
|
||||||
$CALENDARDAYS = array('sunday','monday','tuesday','wednesday','thursday','friday','saturday');
|
$CALENDARDAYS = array('sunday','monday','tuesday','wednesday','thursday','friday','saturday');
|
||||||
|
|
||||||
// Initialize the session variables here to be sure
|
|
||||||
calendar_session_vars();
|
|
||||||
|
|
||||||
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) {
|
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) {
|
||||||
global $CFG, $USER;
|
global $CFG, $USER;
|
||||||
|
@ -1137,23 +1136,18 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$grouparray = array();
|
$grouparray = array();
|
||||||
$groupmodes = NULL;
|
|
||||||
|
|
||||||
// We already have the courses to examine in $courses
|
// We already have the courses to examine in $courses
|
||||||
// For each course...
|
// For each course...
|
||||||
|
|
||||||
|
|
||||||
foreach($groupcourses as $courseid) {
|
foreach($groupcourses as $courseid) {
|
||||||
|
|
||||||
// If the user is an editing teacher in there,
|
// If the user is an editing teacher in there,
|
||||||
if(!empty($USER->id) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
if(!empty($USER->id) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
||||||
|
|
||||||
// The first time we get in here, retrieve all groupmodes at once
|
|
||||||
if($groupmodes === NULL) {
|
|
||||||
$groupmodes = get_records_list('course', 'id', implode(',', $groupcourses), '', 'id, groupmode, groupmodeforce');
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this course has groups, show events from all of them
|
// If this course has groups, show events from all of them
|
||||||
if(isset($groupmodes[$courseid]) && ($groupmodes[$courseid]->groupmode != NOGROUPS || !$groupmodes[$courseid]->groupmodeforce) && ($grouprecords = get_groups($courseid)) !== false) {
|
if(($SESSION->cal_courses_shown[$courseid]->groupmode != NOGROUPS || !$SESSION->cal_courses_shown[$courseid]->groupmodeforce)) {
|
||||||
$grouparray = array_merge($grouparray, array_keys($grouprecords));
|
$groupids[] = $courseid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1165,6 +1159,14 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT id, groupid
|
||||||
|
FROM {$CFG->prefix}groups_courses_groups
|
||||||
|
WHERE courseid IN (".implode(',', $groupids).')';
|
||||||
|
|
||||||
|
$grouprecords= get_records_sql($sql);
|
||||||
|
$grouparray = array_merge($grouparray, array_keys($grouprecords));
|
||||||
|
|
||||||
if(empty($grouparray)) {
|
if(empty($grouparray)) {
|
||||||
$group = false;
|
$group = false;
|
||||||
}
|
}
|
||||||
|
@ -1237,11 +1239,15 @@ function calendar_get_default_courses($ignoreref = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($CFG->adminseesall)) {
|
if (isset($CFG->adminseesall)) {
|
||||||
return get_my_courses($USER->id, 'visible DESC', '*', $CFG->adminseesall);
|
$courses = get_my_courses($USER->id, 'visible DESC', '*', $CFG->adminseesall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return get_my_courses($USER->id, 'visible DESC', '*', false);
|
$courses = get_my_courses($USER->id, 'visible DESC', '*', false);
|
||||||
}
|
}
|
||||||
|
// Make sure global events are included
|
||||||
|
$courses[0] = true;
|
||||||
|
|
||||||
|
return $courses;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calendar_preferences_button() {
|
function calendar_preferences_button() {
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
if ($course->id != SITEID) {
|
if ($course->id != SITEID) {
|
||||||
require_login($course->id);
|
require_login($course->id);
|
||||||
}
|
}
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
|
|
||||||
/// If data submitted, then process and store.
|
/// If data submitted, then process and store.
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,9 @@
|
||||||
$cal_m = optional_param('cal_m');
|
$cal_m = optional_param('cal_m');
|
||||||
$cal_y = optional_param('cal_y');
|
$cal_y = optional_param('cal_y');
|
||||||
|
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
|
|
||||||
switch($var) {
|
switch($var) {
|
||||||
case 'setuser':
|
case 'setuser':
|
||||||
// Not implemented yet (or possibly at all)
|
// Not implemented yet (or possibly at all)
|
||||||
|
|
|
@ -60,6 +60,9 @@
|
||||||
require_login();
|
require_login();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the session variables
|
||||||
|
calendar_session_vars();
|
||||||
|
|
||||||
//add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
|
//add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
|
||||||
$now = usergetdate(time());
|
$now = usergetdate(time());
|
||||||
$pagetitle = '';
|
$pagetitle = '';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue