Skip to content

Commit

Permalink
get_my_courses(): tighten cache scheme - part 2
Browse files Browse the repository at this point in the history
the tighter cache was fragile as we always edit $field
  • Loading branch information
martinlanghoff committed May 6, 2007
1 parent f98c2af commit 309bb40
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/datalib.php
Expand Up @@ -680,13 +680,28 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
* @param int $limit Maximum number of records to return, or 0 for unlimited
* @return array {@link $COURSE} of course objects
*/
function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields='*', $doanything=false,$limit=0) {
function get_my_courses($userid, $sort=NULL, $fields=NULL, $doanything=false,$limit=0) {

global $USER;

// Default parameters
$d_sort = 'visible DESC,sortorder ASC';
$d_fields = '*';

$usingdefaults = true;
if (is_null($sort)) {
$sort = $d_sort;
} else {
$usingdefaults = false;
}
if (is_null($fields)) {
$fields = $d_fields;
} else {
$usingdefaults = false;
}

// If using default params, we may have it cached...
if (!empty($USER->id) && ($USER->id == $userid)
&& $sort==='visible DESC,sortorder ASC' && $fields==='*') {
if (!empty($USER->id) && ($USER->id == $userid) && $usingdefaults) {
if (!empty($USER->mycourses[$doanything])) {
return $USER->mycourses[$doanything];
}
Expand Down Expand Up @@ -822,9 +837,8 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields='*'
}
}

// MDL-9671, my courses should only get cached when '*' is chosen as the field, otherwise courses
// can not be displayed properly as cached courses might contain missing course name etc
if (!empty($USER->id) && ($USER->id == $userid) && $fields==='*') {
// Cache if using default params...
if (!empty($USER->id) && ($USER->id == $userid) && $usingdefaults) {
$USER->mycourses[$doanything] = $mycourses;
}

Expand Down

0 comments on commit 309bb40

Please sign in to comment.