From: moodler
Date: Tue, 19 Aug 2003 09:26:36 +0000 (+0000)
Subject: The number of courses in the categories is now cached in the
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9936fe81eaa7028f6b9cd25b55d902966a444626;p=moodle.git
The number of courses in the categories is now cached in the
the category, and only updated when courses are moved/added/deleted etc
or the admin looks at the category listing
---
diff --git a/course/index.php b/course/index.php
index 7636d6d5d6..995d4d0ecb 100644
--- a/course/index.php
+++ b/course/index.php
@@ -303,9 +303,7 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $
echo "
";
echo "";
- echo ""; /// Print little icons
- echo count_records("course", "category", $category->id);
- echo " | ";
+ echo "$category->coursecount | ";
echo ""; /// Print little icons
diff --git a/course/lib.php b/course/lib.php
index d20343e07d..7bb3fe37ca 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -930,8 +930,8 @@ function print_category_info($category, $depth) {
}
echo " | ";
echo "";
- if ($count = count_records("course", "category", $category->id)) {
- echo $count;
+ if ($category->coursecount) {
+ echo $category->coursecount;
}
echo " | ";
echo "";
diff --git a/lib/datalib.php b/lib/datalib.php
index d0fb17d173..3092328baf 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1264,6 +1264,7 @@ function fix_course_sortorder($categoryid, $sort="sortorder ASC") {
if ($modified) {
set_field("course_categories", "timemodified", time(), "id", $categoryid);
}
+ set_field("course_categories", "coursecount", $count, "id", $categoryid);
return true;
}
diff --git a/lib/db/mysql.php b/lib/db/mysql.php
index 0973745577..97e5ddc330 100644
--- a/lib/db/mysql.php
+++ b/lib/db/mysql.php
@@ -486,6 +486,10 @@ function main_upgrade($oldversion=0) {
table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
}
+ if ($oldversion < 2003081900) {
+ table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
+ }
+
return $result;
}
diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql
index a770ca226f..f5fc2be7d5 100644
--- a/lib/db/mysql.sql
+++ b/lib/db/mysql.sql
@@ -64,7 +64,7 @@ CREATE TABLE `prefix_course_categories` (
`description` text NOT NULL,
`parent` int(10) unsigned NOT NULL default '0',
`sortorder` int(10) unsigned NOT NULL default '0',
- `courseorder` int(10) unsigned NOT NULL default '0',
+ `coursecount` int(10) unsigned NOT NULL default '0',
`visible` tinyint(1) NOT NULL default '1',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php
index 38a2f5e5d7..c06456b3d9 100644
--- a/lib/db/postgres7.php
+++ b/lib/db/postgres7.php
@@ -230,6 +230,10 @@ function main_upgrade($oldversion=0) {
table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
}
+ if ($oldversion < 2003081900) {
+ table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
+ }
+
return $result;
}
?>
diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql
index bc615cbb52..ec58e3d648 100644
--- a/lib/db/postgres7.sql
+++ b/lib/db/postgres7.sql
@@ -35,7 +35,7 @@ CREATE TABLE prefix_course_categories (
description text NOT NULL default '',
parent integer NOT NULL default '0',
sortorder integer NOT NULL default '0',
- courseorder integer NOT NULL default '0',
+ coursecount integer NOT NULL default '0',
visible integer NOT NULL default '1',
timemodified` integer NOT NULL default '0'
);
diff --git a/version.php b/version.php
index 478eba8247..888429317e 100644
--- a/version.php
+++ b/version.php
@@ -5,7 +5,7 @@
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
-$version = 2003081800; // The current version is a date (YYYYMMDDXX)
+$version = 2003081900; // The current version is a date (YYYYMMDDXX)
$release = "1.1 alpha"; // User-friendly version number