commit d606d3505aa3f7299a5d5b0ef6e5fa825f5bd0f7
Author: Francois Marier <francois@catalyst.net.nz>
Date:   Thu May 14 15:22:17 2009 +1200

    course/lib: optimise print_category by caching the query counting the total number of courses on the site

diff --git a/course/lib.php b/course/lib.php
index 6efda55..c60ee5c 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1742,7 +1742,12 @@ function print_category_info($category, $depth, $files = false, $onclick = '', $
 
     $catlinkcss = $category->visible ? '' : ' class="dimmed" ';
 
-    $coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
+    static $coursecount = null;
+    if (null === $coursecount) {
+        // only need to check this once
+        $coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
+    }
+
     if ($files and $coursecount) {
         $catimage = '<img src="'.$CFG->pixpath.'/i/course.gif" alt="" />';
     } else {
