Skip to content
Browse files

Optimisation for scales page - cache array of courses for site_scale_…

…used
  • Loading branch information...
1 parent 61f7795 commit 3644b6dca1aa84dc72d630057b8123b3a16e7dcc mjollnir_ committed
Showing with 14 additions and 9 deletions.
  1. +8 −5 course/scales.php
  2. +6 −4 lib/moodlelib.php
View
13 course/scales.php
@@ -39,6 +39,9 @@
$stroptions = get_string("action");
$strtype = get_string("group");
+ /// init this here so we can pass it by reference to every call to site_scale_used to avoid getting the courses out of the db over and over again
+ $courses = array();
+
/// If scale data is being submitted, then save it and continue
$errors = NULL;
@@ -99,7 +102,7 @@
}
$scales_course_uses = course_scale_used($course->id,$scale->id);
- $scales_site_uses = site_scale_used($scale->id);
+ $scales_site_uses = site_scale_used($scale->id,$courses);
$scalemenu = make_menu_from_list($scale->scale);
print_header("$course->shortname: $strscales", "$course->fullname",
@@ -146,7 +149,7 @@
//Calculate the uses
if ($scale->courseid == 0) {
- $scale_uses = site_scale_used($scale->id);
+ $scale_uses = site_scale_used($scale->id,$courses);
} else {
$scale_uses = course_scale_used($course->id,$scale->id);
}
@@ -246,7 +249,7 @@
//Calculate the uses
if ($scale->courseid == 0) {
- $scale_uses = site_scale_used($scale->id);
+ $scale_uses = site_scale_used($scale->id,$courses);
} else {
$scale_uses = course_scale_used($course->id,$scale->id);
}
@@ -279,7 +282,7 @@
//Calculate the uses
if ($scale->courseid == 0) {
- $scale_uses = site_scale_used($scale->id);
+ $scale_uses = site_scale_used($scale->id,$courses);
} else {
$scale_uses = course_scale_used($course->id,$scale->id);
}
@@ -440,7 +443,7 @@
if (!empty($scale->courseid)) {
$scales_uses = course_scale_used($course->id,$scale->id);
} else {
- $scales_uses = site_scale_used($scale->id);
+ $scales_uses = site_scale_used($scale->id,$courses);
}
$line[] = $scales_uses;
if ($incustom) {
View
10 lib/moodlelib.php
@@ -3067,7 +3067,7 @@ function course_scale_used($courseid,$scaleid) {
return $return;
}
-function site_scale_used($scaleid) {
+function site_scale_used($scaleid,&$courses) {
////This function returns the nummber of activities
////using scaleid in the entire site
@@ -3076,9 +3076,11 @@ function site_scale_used($scaleid) {
$return = 0;
if (!empty($scaleid)) {
- if ($courses = get_courses()) {
- foreach ($courses as $course) {
- $return += course_scale_used($course->id,$scaleid);
+ if (!is_array($courses) || count($courses) == 0) {
+ if ($courses = get_courses("all","c.sortorder ASC","c.id,c.shortname")) {
+ foreach ($courses as $course) {
+ $return += course_scale_used($course->id,$scaleid);
+ }
}
}
}

0 comments on commit 3644b6d

Please sign in to comment.
Something went wrong with that request. Please try again.