From b3e4fbc011f0043ad24fe0ceed5501b5ad711f24 Mon Sep 17 00:00:00 2001 From: Adam Olley Date: Mon, 6 Mar 2017 11:59:19 +1030 Subject: [PATCH] MDL-58160 coursecat: Use set_many to populate category cache When the course category cache needs to be repopulated, two entries are added to the cache for each category. In core this is currently done in a for-loop, resulting in N set calls to the cache (where N is twice the number of categories in Moodle). This change switches that code to using a single set_many cache call instead, which makes this an O(1) operation instead of O(N). For a site with say, 1000 categories, this results in only 1 set call to the cachestore instead of 2000. --- lib/coursecatlib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/coursecatlib.php b/lib/coursecatlib.php index d8ce7b8cfa9..e5edde1a17b 100644 --- a/lib/coursecatlib.php +++ b/lib/coursecatlib.php @@ -626,9 +626,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { } // We must add countall to all in case it was the requested ID. $all['countall'] = $count; - foreach ($all as $key => $children) { - $coursecattreecache->set($key, $children); - } + $coursecattreecache->set_many($all); if (array_key_exists($id, $all)) { return $all[$id]; }