From c5d13b689f39ccd32b184b551da6835fb33f5b21 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:27:08 +0000 Subject: [PATCH] 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. --- lib/datalib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 -- 2.39.5