From 2f1e7982df1b44246ed33e1f7d2fff90fa5a8d58 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 15 Aug 2022 15:01:58 +0100 Subject: [PATCH] MDL-67020 Cache: Refactor build_course_cache --- lib/modinfolib.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/modinfolib.php b/lib/modinfolib.php index 94f2dfb4452..d0eb3e29b8b 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -475,18 +475,7 @@ class course_modinfo { // partial rebuild logic sometimes sets the $coursemodinfo->cacherev to -1 which is an // indicator that it needs rebuilding. if ($coursemodinfo === false || ($course->cacherev > $coursemodinfo->cacherev)) { - $cachekey = $course->id; - $lock = $cachecoursemodinfo->acquire_lock($cachekey); - try { - // Only actually do the build if it's still needed after getting the lock (not if - // somebody else, who might have been holding the lock, built it already). - $coursemodinfo = $cachecoursemodinfo->get_versioned($course->id, $course->cacherev); - if ($coursemodinfo === false || ($course->cacherev > $coursemodinfo->cacherev)) { - $coursemodinfo = self::inner_build_course_cache($course, $lock); - } - } finally { - $cachecoursemodinfo->release_lock($cachekey); - } + $coursemodinfo = self::build_course_cache($course); } // Set initial values @@ -653,10 +642,16 @@ class course_modinfo { $cachekey = $course->id; $cachecoursemodinfo->acquire_lock($cachekey); try { - return self::inner_build_course_cache($course, $partialrebuild); + // Only actually do the build if it's still needed after getting the lock (not if + // somebody else, who might have been holding the lock, built it already). + $coursemodinfo = $cachecoursemodinfo->get_versioned($course->id, $course->cacherev); + if ($coursemodinfo === false || ($course->cacherev > $coursemodinfo->cacherev)) { + $coursemodinfo = self::inner_build_course_cache($course); + } } finally { $cachecoursemodinfo->release_lock($cachekey); } + return $coursemodinfo; } /**