Skip to content

Commit

Permalink
feat(settings): improve performance by evaluating all strings in the …
Browse files Browse the repository at this point in the history
…admin settings tree only if they are actually displayed
  • Loading branch information
jboulen committed Jul 5, 2024
1 parent cae76db commit 89c4c3c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,56 @@
defined('MOODLE_INTERNAL') || die;

if ($hassiteconfig) {
$settings = new admin_settingpage('local_debugtoolbar', get_string('pluginname', 'local_debugtoolbar'));
$settings = new admin_settingpage('local_debugtoolbar', new lang_string('pluginname', 'local_debugtoolbar'));
$ADMIN->add('localplugins', $settings);

// Note : We always add the custom admin_settingpage to the tree, but the actual settings are added to that page
// only when $ADMIN->fulltree is set. This is to improve performance when the caller does not need the actual settings
// but only the administration pages structure (source : https://moodledev.io/docs/4.4/apis/subsystems/admin).
if ($ADMIN->fulltree) {
// Add warnings about usage.
$content = html_writer::tag('div', get_string('usage_warning', 'local_debugtoolbar'), ['class' => 'alert alert-warning']);
$settings->add(new admin_setting_heading('local_debugtoolbar/header', get_string('settings'), $content));
$content = html_writer::tag('div', new lang_string('usage_warning', 'local_debugtoolbar'), ['class' => 'alert alert-warning']);
$settings->add(new admin_setting_heading('local_debugtoolbar/header', new lang_string('settings'), $content));

// Add a checkbox to enable/disable module.
$name = 'local_debugtoolbar/enable';
$label = get_string('enable_debugtoolbar', 'local_debugtoolbar');
$label = new lang_string('enable_debugtoolbar', 'local_debugtoolbar');
$description = '';
$default = 0;
$settings->add(new admin_setting_plugin_activation($name, $label, $description, $default));

// Add a checkbox to enable/disable error handler.
$name = 'local_debugtoolbar/enable_error_handler';
$label = get_string('enable_error_handler', 'local_debugtoolbar');
$description = get_string('enable_error_handler_description', 'local_debugtoolbar');
$label = new lang_string('enable_error_handler', 'local_debugtoolbar');
$description = new lang_string('enable_error_handler_description', 'local_debugtoolbar');
$default = 0;
$settings->add(new admin_setting_configcheckbox($name, $label, $description, $default));

// Add a field to set execution time warning threshold.
$name = 'local_debugtoolbar/realtime_warning_threshold';
$label = get_string('realtime_warning_threshold', 'local_debugtoolbar');
$description = get_string('realtime_warning_threshold_description', 'local_debugtoolbar');
$label = new lang_string('realtime_warning_threshold', 'local_debugtoolbar');
$description = new lang_string('realtime_warning_threshold_description', 'local_debugtoolbar');
$default = .2;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_FLOAT));

// Add a field to set execution time critical threshold.
$name = 'local_debugtoolbar/realtime_critical_threshold';
$label = get_string('realtime_critical_threshold', 'local_debugtoolbar');
$description = get_string('realtime_critical_threshold_description', 'local_debugtoolbar');
$label = new lang_string('realtime_critical_threshold', 'local_debugtoolbar');
$description = new lang_string('realtime_critical_threshold_description', 'local_debugtoolbar');
$default = 2;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_FLOAT));

// Add a field to set database queries warning threshold.
$name = 'local_debugtoolbar/dbqueries_warning_threshold';
$label = get_string('dbqueries_warning_threshold', 'local_debugtoolbar');
$description = get_string('dbqueries_warning_threshold_description', 'local_debugtoolbar');
$label = new lang_string('dbqueries_warning_threshold', 'local_debugtoolbar');
$description = new lang_string('dbqueries_warning_threshold_description', 'local_debugtoolbar');
$default = 50;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_INT));

// Add a field to set database queries critical threshold.
$name = 'local_debugtoolbar/dbqueries_critical_threshold';
$label = get_string('dbqueries_critical_threshold', 'local_debugtoolbar');
$description = get_string('dbqueries_critical_threshold_description', 'local_debugtoolbar');
$label = new lang_string('dbqueries_critical_threshold', 'local_debugtoolbar');
$description = new lang_string('dbqueries_critical_threshold_description', 'local_debugtoolbar');
$default = 100;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_INT));
}
Expand Down

0 comments on commit 89c4c3c

Please sign in to comment.