Skip to content

Commit

Permalink
Purge the caches and lock protection - #114.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Nov 12, 2021
1 parent c96f629 commit 9dc01fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions classes/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lang/en/format_topcoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand All @@ -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.';
Expand Down
8 changes: 6 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9dc01fb

Please sign in to comment.