From: martinlanghoff Date: Wed, 19 Sep 2007 07:27:08 +0000 (+0000) Subject: datalib: fix_course_sortorder() - minor optimisation X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c5d13b689f39ccd32b184b551da6835fb33f5b21;p=moodle.git datalib: fix_course_sortorder() - minor optimisation Don't update fields unnecessarily. Cuts 3 DB queries per category on course/index page (45 in a 15 category setup). fix_course_sortorder() should be fixed to avoid recursion. --- diff --git a/lib/datalib.php b/lib/datalib.php index 50a71f7a2b..a81044a387 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1237,8 +1237,12 @@ function fix_course_sortorder($categoryid=0, $n=0, $safe=0, $depth=0, $path='') $path = $path . '/' . $categoryid; $depth = $depth + 1; - set_field('course_categories', 'path', addslashes($path), 'id', $categoryid); - set_field('course_categories', 'depth', $depth, 'id', $categoryid); + if ($cat->path !== $path) { + set_field('course_categories', 'path', addslashes($path), 'id', $categoryid); + } + if ($cat->depth != $depth) { + set_field('course_categories', 'depth', $depth, 'id', $categoryid); + } } // get some basic info about courses in the category