MDL-72991 Course: Partial course cache rebuild

When updating/deleting a section/module, the system now only
invalidate of the element (section/module), not the whole course cache
Also, the system now only recalculate the cache for element (section/module)
if necessary, not the whole course cache

Move module/section purging to course_modinfo:
  + course_modinfo::purge_course_section_cache_by_id was created to purge section by id
  + course_modinfo::purge_course_section_cache_by_number was created to purge section by number
  + course_modinfo::purge_course_module_cache was created to purge module
This commit is contained in:
Dongsheng Cai
2022-03-17 15:34:01 +07:00
committed by Huong Nguyen
parent 967d9b2546
commit f97b86e841
17 changed files with 458 additions and 181 deletions
+14 -3
View File
@@ -1095,7 +1095,15 @@ abstract class base {
}
}
if ($needrebuild) {
rebuild_course_cache($this->courseid, true);
if ($sectionid) {
// Invalidate the section cache by given section id.
course_modinfo::purge_course_section_cache_by_id($this->courseid, $sectionid);
// Partial rebuild sections that have been invalidated.
rebuild_course_cache($this->courseid, true, true);
} else {
// Full rebuild if sectionid is null.
rebuild_course_cache($this->courseid);
}
}
if ($changed) {
// Reset internal caches.
@@ -1385,7 +1393,7 @@ abstract class base {
}
if (!is_object($section)) {
$section = $DB->get_record('course_sections', array('course' => $this->get_courseid(), 'section' => $section),
'id,section,sequence,summary');
'id,course,section,sequence,summary');
}
if (!$section || !$section->section) {
// Not possible to delete 0-section.
@@ -1422,7 +1430,10 @@ abstract class base {
// Delete section and it's format options.
$DB->delete_records('course_format_options', array('sectionid' => $section->id));
$DB->delete_records('course_sections', array('id' => $section->id));
rebuild_course_cache($course->id, true);
// Invalidate the section cache by given section id.
course_modinfo::purge_course_section_cache_by_id($course->id, $section->id);
// Partial rebuild section cache that has been purged.
rebuild_course_cache($course->id, true, true);
// Delete section summary files.
$context = \context_course::instance($course->id);