]> git.mjollnir.org Git - moodle.git/commitdiff
calendar: performance optimisations + behaviour fix (MDL-7416 MDL-9617)
authormartinlanghoff <martinlanghoff>
Sun, 6 May 2007 04:28:11 +0000 (04:28 +0000)
committermartinlanghoff <martinlanghoff>
Sun, 6 May 2007 04:28:11 +0000 (04:28 +0000)
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

blocks/calendar_month/block_calendar_month.php
blocks/calendar_upcoming/block_calendar_upcoming.php
calendar/event.php
calendar/export.php
calendar/lib.php
calendar/preferences.php
calendar/set.php
calendar/view.php

index ad4ed09e0d331465acd0a7a82df0d3b4d1cea9b2..dd5debbc8a1e0ff2601fae51c867177728cd9fb1 100644 (file)
@@ -20,7 +20,9 @@ class block_calendar_month extends block_base {
         if ($this->content !== NULL) {
             return $this->content;
         }
-
+        // Initialize the session variables
+        calendar_session_vars();
+        
         $this->content = new stdClass;
         $this->content->text = '';
         $this->content->footer = '';
index f0e1566b80fe71042c7d8dc849103ad3f4d29118..f7d4770896b936f67ed1f7d8c55d17fc8b4bca84 100644 (file)
@@ -16,7 +16,8 @@ class block_calendar_upcoming extends block_base {
         if ($this->content !== NULL) {
             return $this->content;
         }
-
+        // Initialize the session variables
+        calendar_session_vars();
         $this->content = new stdClass;
         $this->content->text = '';
 
index 472e3b70d82c4291b92bbcbd6f30d280a88f73d2..a3fe5e3c4165c5ffbfcffd404af07c6b2feeae20 100644 (file)
@@ -66,6 +66,9 @@
 
     $strcalendar = get_string('calendar', 'calendar');
 
+    // Initialize the session variables
+    calendar_session_vars();
+
     $now = usergetdate(time());
     $nav = calendar_get_link_tag($strcalendar, CALENDAR_URL.'view.php?view=upcoming&amp;', $now['mday'], $now['mon'], $now['year']);
     $day = intval($now['mday']);
index 9a73b3b8776896a9a36b8825d57495c9d929fc11..e7caced2ce502b490288853433ff3bdaee161e26 100644 (file)
@@ -17,6 +17,9 @@ if(!$site = get_site()) {
     redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
 }
 
+// Initialize the session variables
+calendar_session_vars();
+
 $pagetitle = get_string('export', 'calendar');
 $now = usergetdate(time());
 $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&amp;', $now['mday'], $now['mon'], $now['year']).' -> '.$pagetitle;
index 8cfbbfb724bdf83a1be3128df7bb18a89ab1d251..5939ac7c1a844eb091a52d34bd321ab8e2791e37 100644 (file)
@@ -64,8 +64,7 @@ define ('CALENDAR_TF_12', '%I:%M %p');
 
 $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) {
     global $CFG, $USER;
@@ -1137,23 +1136,18 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
         }
         else {
             $grouparray = array();
-            $groupmodes = NULL;
 
             // We already have the courses to examine in $courses
             // For each course...
+
+            
             foreach($groupcourses as $courseid) {
 
                 // If the user is an editing teacher in there,
                 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(isset($groupmodes[$courseid]) && ($groupmodes[$courseid]->groupmode != NOGROUPS || !$groupmodes[$courseid]->groupmodeforce) && ($grouprecords = get_groups($courseid)) !== false) {
-                        $grouparray = array_merge($grouparray, array_keys($grouprecords));
+                    if(($SESSION->cal_courses_shown[$courseid]->groupmode != NOGROUPS || !$SESSION->cal_courses_shown[$courseid]->groupmodeforce)) {
+                        $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)) {
                 $group = false;
             }
@@ -1237,11 +1239,15 @@ function calendar_get_default_courses($ignoreref = false) {
     }
     
     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 {
-        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() {
index e168acf839353214ff1fd30b7c6467744ced7994..048fb99974360484415c5ee1239d9d72468e2010 100644 (file)
@@ -13,7 +13,9 @@
     if ($course->id != SITEID) {
         require_login($course->id);
     }
-
+    // Initialize the session variables
+    calendar_session_vars();
+    
 /// If data submitted, then process and store.
 
     if ($form = data_submitted()) {
index 267bddc93974f21e6604a46bd1d15c0d6b679100..9835770e5f19e541079ed8b703747c8ac98756dc 100644 (file)
@@ -49,6 +49,9 @@
     $cal_m = optional_param('cal_m');
     $cal_y = optional_param('cal_y');
 
+    // Initialize the session variables
+    calendar_session_vars();
+
     switch($var) {
         case 'setuser':
             // Not implemented yet (or possibly at all)
index bd16f659a9579988398bfe3c6d9f920b92886cb6..8fe19f658b59f1aa0c2c3b780990680bb4b703d6 100644 (file)
@@ -60,6 +60,9 @@
         require_login();
     }
 
+    // Initialize the session variables
+    calendar_session_vars();
+
     //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
     $now = usergetdate(time());
     $pagetitle = '';