From a7a04f6d628942f3fc5df22a394c9648a2f7ce37 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Sun, 11 Aug 2013 22:38:16 +1000 Subject: [PATCH] MDL-41114 Avoid unnecessary retrieving of coursecat from DB - course category depth can be estimated in make_categories_options() by the number of separators --- course/lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/course/lib.php b/course/lib.php index 609235060ae..ee8019fb62b 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1236,9 +1236,10 @@ function get_category_or_system_context($categoryid) { function make_categories_options() { global $CFG; require_once($CFG->libdir. '/coursecatlib.php'); - $cats = coursecat::make_categories_list(); + $cats = coursecat::make_categories_list('', 0, ' / '); foreach ($cats as $key => $value) { - $cats[$key] = str_repeat(' ', coursecat::get($key)->depth - 1). $value; + // Prefix the value with the number of spaces equal to category depth (number of separators in the value). + $cats[$key] = str_repeat(' ', substr_count($value, ' / ')). $value; } return $cats; } -- 2.43.0