Skip to content

Commit

Permalink
MDL-58160 coursecat: Use set_many to populate category cache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aolley committed Mar 6, 2017
1 parent 3c45d26 commit b3e4fbc
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/coursecatlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,7 @@ protected static function get_tree($id) {
}
// 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];
}
Expand Down

0 comments on commit b3e4fbc

Please sign in to comment.