Index: lib/dml/moodle_database.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/dml/moodle_database.php,v
retrieving revision 1.134
diff -u -r1.134 moodle_database.php
--- lib/dml/moodle_database.php	2 Feb 2011 13:20:26 -0000	1.134
+++ lib/dml/moodle_database.php	18 Feb 2011 13:45:57 -0000
@@ -1464,8 +1464,16 @@
      * @throws dml_exception if error
      */
     public function count_records($table, array $conditions=null) {
+        static $cache = array();
+        if (empty($conditions) && isset($cache[$table])) {
+            return $cache[$table];
+        }
         list($select, $params) = $this->where_clause($table, $conditions);
-        return $this->count_records_select($table, $select, $params);
+        $count = $this->count_records_select($table, $select, $params);
+        if (empty($conditions)) {
+            $cache[$table] = $count;
+        }
+        return $count;
     }
 
     /**
