From 6b0b05b32f3fd86b9814ce03fb0456ef4c1d8c2f Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 27 Sep 2013 15:32:27 +1000 Subject: [PATCH] MDL-41942 course: Allow course listings to work with caches disabled --- lib/coursecatlib.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/coursecatlib.php b/lib/coursecatlib.php index 53481125ca5..520840e3d39 100644 --- a/lib/coursecatlib.php +++ b/lib/coursecatlib.php @@ -572,12 +572,6 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { if ($rv !== false) { return $rv; } - // We did not find the entry in cache but it also can mean that tree is not built. - // The keys 0 and 'countall' must always be present if tree is built. - if ($id !== 0 && $id !== 'countall' && $coursecattreecache->has('countall')) { - // Tree was built, it means the non-existing $id was requested. - return false; - } // Re-build the tree. $sql = "SELECT cc.id, cc.parent, cc.visible FROM {course_categories} cc @@ -619,7 +613,8 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { if (array_key_exists($id, $all)) { return $all[$id]; } - return false; + // Requested non-existing category. + return array(); } /** @@ -1187,8 +1182,13 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { $coursecatcache = cache::make('core', 'coursecat'); $cntcachekey = 'scnt-'. serialize($search); if (($cnt = $coursecatcache->get($cntcachekey)) === false) { - self::search_courses($search, $options); - $cnt = $coursecatcache->get($cntcachekey); + // Cached value not found. Retrieve ALL courses and return their count. + unset($options['offset']); + unset($options['limit']); + unset($options['summary']); + unset($options['coursecontacts']); + $courses = self::search_courses($search, $options); + $cnt = count($courses); } return $cnt; } @@ -1311,8 +1311,13 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { $cntcachekey = 'lcnt-'. $this->id. '-'. (!empty($options['recursive']) ? 'r' : ''); $coursecatcache = cache::make('core', 'coursecat'); if (($cnt = $coursecatcache->get($cntcachekey)) === false) { - $this->get_courses($options); - $cnt = $coursecatcache->get($cntcachekey); + // Cached value not found. Retrieve ALL courses and return their count. + unset($options['offset']); + unset($options['limit']); + unset($options['summary']); + unset($options['coursecontacts']); + $courses = $this->get_courses($options); + $cnt = count($courses); } return $cnt; } -- 2.43.0