From 9dc01fba7c4f659e89a36427321fcf8c613bbd1a Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Fri, 12 Nov 2021 21:09:24 +0000 Subject: [PATCH] Purge the caches and lock protection - #114. --- classes/activity.php | 11 +++++++++++ lang/en/format_topcoll.php | 4 ++-- settings.php | 8 ++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/classes/activity.php b/classes/activity.php index 4ee93254..e3b718f1 100644 --- a/classes/activity.php +++ b/classes/activity.php @@ -595,8 +595,11 @@ protected static function course_participant_count($courseid, $mod) { // New users? $usercreatedcache = \cache::make('format_topcoll', 'activityusercreatedcache'); $createdusers = $usercreatedcache->get($courseid); + $lock = null; $newstudents = array(); if (!empty($createdusers)) { + $lock = self::lockcaches($courseid); + $studentrolescache = \cache::make('format_topcoll', 'activitystudentrolescache'); $studentroles = $studentrolescache->get('roles'); $context = \context_course::instance($courseid); @@ -653,9 +656,17 @@ protected static function course_participant_count($courseid, $mod) { $modulecountcache->set($courseid, $modulecountcourse); } + if (!is_null($lock)) { + $lock->release(); + } + return $modulecountcourse[$mod->id][0]; } + if (!is_null($lock)) { + $lock->release(); + } + return 0; } diff --git a/lang/en/format_topcoll.php b/lang/en/format_topcoll.php index f3ae6229..1a534015 100644 --- a/lang/en/format_topcoll.php +++ b/lang/en/format_topcoll.php @@ -118,7 +118,7 @@ // Coursesetting - Show addtional data for modules. $string['enableadditionalmoddata'] = 'Enable additional information'; -$string['enableadditionalmoddatadesc'] = 'This is a \'Site level\' switch to turn the activity information on or off. It needs to be \'on\' for the related settings that operate at a course level to take effect. As this functionality can be computationally expensive, then it is strongly suggested that you undertake full testing before using on a production system.'; +$string['enableadditionalmoddatadesc'] = 'This is a \'Site level\' switch to turn the activity information on or off. It needs to be \'on\' for the related settings that operate at a course level to take effect. As this functionality can be computationally expensive, then it is strongly suggested that you undertake full testing before using on a production system. Note: Purges the cache caches when changed.'; $string['showadditionalmoddata'] = 'Show additional information for: {$a} in the course'; $string['showadditionalmoddata_help'] = 'Allow all users to see the activity deadline and users with grading permission to see the number of submissions on the course page for activities.'; @@ -130,7 +130,7 @@ $string['resetallactivitymeta_help'] = 'Resets all the additional module information to follow the site default value.'; $string['courseadditionalmoddatamaxstudents'] = 'Set the maximum number of students on a course that \'Show additional information\' will apply to'; -$string['courseadditionalmoddatamaxstudentsdesc'] = 'Additional information can take time to calculate, especially on large courses, so here you can set the maximum number of students that a couse can have for the functionality to show on that course. Above that value, the \'Additional information\' will NOT be calculated or show regardless of the course settings! A value of \'0\' means \'unlimited\'.'; +$string['courseadditionalmoddatamaxstudentsdesc'] = 'Additional information can take time to calculate, especially on large courses, so here you can set the maximum number of students that a couse can have for the functionality to show on that course. Above that value, the \'Additional information\' will NOT be calculated or show regardless of the course settings! A value of \'0\' means \'unlimited\'. Note: Purges the cache caches when changed.'; $string['courseadditionalmoddatastudentsinfo'] = 'Additional information status:'; $string['courseadditionalmoddatastudentsinfounlimited'] = 'Additional information will show for the enabled activities for {$a} students.'; diff --git a/settings.php b/settings.php index 77c1c76d..934778a2 100644 --- a/settings.php +++ b/settings.php @@ -516,13 +516,17 @@ 1 => new lang_string('no'), 2 => new lang_string('yes') ); - $settings->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + $setting = new admin_setting_configselect($name, $title, $description, $default, $choices); + $setting->set_updatedcallback('cache_helper::purge_all'); + $settings->add($setting); $name = 'format_topcoll/courseadditionalmoddatamaxstudents'; $title = get_string('courseadditionalmoddatamaxstudents', 'format_topcoll'); $description = get_string('courseadditionalmoddatamaxstudentsdesc', 'format_topcoll'); $default = 0; - $settings->add(new admin_setting_configtext($name, $title, $description, $default, PARAM_INT)); + $setting = new admin_setting_configtext($name, $title, $description, $default, PARAM_INT); + $setting->set_updatedcallback('cache_helper::purge_all'); + $settings->add($setting); $name = 'format_topcoll/defaultshowadditionalmoddata'; $title = get_string('defaultshowadditionalmoddata', 'format_topcoll');