Skip to content
Browse files

admin/modules: Avoid calling rebuild_course_cache()

rebuild_course_cache() over all courses is extremely expensive,
not suitable for interactive calling. Better to clear modinfo
and let course/view.php repopulate it as needed.

With this patch we clear out modinfo _only_ for courses affected
by the module we show/hide/delete.
  • Loading branch information...
1 parent f6297ed commit cfca081765e6c7fb23455d7cd2d34c30638788e0 martinlanghoff committed Sep 12, 2007
Showing with 36 additions and 19 deletions.
  1. +36 −19 admin/modules.php
View
55 admin/modules.php
@@ -34,29 +34,45 @@
print_heading($stractivities);
- $coursesaffected = false;
-
-
/// If data submitted, then process and store.
if (!empty($hide) and confirm_sesskey()) {
if (!$module = get_record("modules", "name", $hide)) {
error("Module doesn't exist!");
}
- set_field("modules", "visible", "0", "id", $module->id); // Hide main module
- set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id); // Remember the previous visible state so we can toggle this back if the module is unhidden.
- set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id);
- set_field("course_modules", "visible", "0", "module", $module->id); // Hide all related activity modules
- $coursesaffected = true;
+ set_field("modules", "visible", "0", "id", $module->id); // Hide main module
+ // Remember the visibility status in visibleold
+ // and hide...
+ $sql = "UPDATE {$CFG->prefix}course_modules
+ SET visibleold=visible,
+ visible=0
+ WHERE module={$module->id}";
+ execute_sql($sql, false);
+ // clear the course modinfo cache for courses
+ // where we just deleted something
+ $sql = "UPDATE {$CFG->prefix}course
+ SET modinfo=''
+ WHERE id IN (SELECT DISTINCT course
+ FROM {$CFG->prefix}course_modules
+ WHERE visibleold=1 AND module={$module->id})";
+ execute_sql($sql, false);
}
if (!empty($show) and confirm_sesskey()) {
if (!$module = get_record("modules", "name", $show)) {
error("Module doesn't exist!");
}
- set_field("modules", "visible", "1", "id", $module->id); // Show main module
- set_field('course_modules', 'visible', '1', 'visibleold', '1', 'module', $module->id); // Get the previous saved visible state for the course module.
- $coursesaffected = true;
+ set_field("modules", "visible", "1", "id", $module->id); // Show main module
+ set_field('course_modules', 'visible', '1', 'visibleold',
+ '1', 'module', $module->id); // Get the previous saved visible state for the course module.
+ // clear the course modinfo cache for courses
+ // where we just made something visible
+ $sql = "UPDATE {$CFG->prefix}course
+ SET modinfo=''
+ WHERE id IN (SELECT DISTINCT course
+ FROM {$CFG->prefix}course_modules
+ WHERE visible=1 AND module={$module->id})";
+ execute_sql($sql, false);
}
if (!empty($delete) and confirm_sesskey()) {
@@ -89,6 +105,15 @@
}
}
+ // clear course.modinfo for courses
+ // that used this module...
+ $sql = "UPDATE {$CFG->prefix}course
+ SET modinfo=''
+ WHERE id IN (SELECT DISTINCT course
+ FROM {$CFG->prefix}course_modules
+ WHERE module={$module->id})";
+ execute_sql($sql, false);
+
// Now delete all the course module records
if (!delete_records("course_modules", "module", $module->id)) {
notify("Error occurred while deleting all $strmodulename records in course_modules table");
@@ -124,20 +149,12 @@
// Delete the capabilities that were defined by this module
capabilities_cleanup('mod/'.$module->name);
- // rebuild_course_cache(); // Because things have changed
- $coursesaffected = true;
-
$a->module = $strmodulename;
$a->directory = "$CFG->dirroot/mod/$delete";
notice(get_string("moduledeletefiles", "", $a), "modules.php");
}
}
- if ($coursesaffected) {
- rebuild_course_cache(); // Because things have changed
- }
-
-
/// Get and sort the existing modules
if (!$modules = get_records("modules")) {

0 comments on commit cfca081

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