Skip to content

Commit

Permalink
feat(settings): improve performance when we do not need the actual se…
Browse files Browse the repository at this point in the history
…ttings but only the administration pages structure
  • Loading branch information
jboulen committed Jul 5, 2024
1 parent 3b02e48 commit cae76db
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,54 @@
$settings = new admin_settingpage('local_debugtoolbar', get_string('pluginname', 'local_debugtoolbar'));
$ADMIN->add('localplugins', $settings);

// 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));
// 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));

// Add a checkbox to enable/disable module.
$name = 'local_debugtoolbar/enable';
$label = get_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 module.
$name = 'local_debugtoolbar/enable';
$label = get_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');
$default = 0;
$settings->add(new admin_setting_configcheckbox($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');
$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');
$default = .2;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_FLOAT));
// 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');
$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');
$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');
$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');
$default = 50;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_INT));
// 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');
$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');
$default = 100;
$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');
$default = 100;
$settings->add(new admin_setting_configtext($name, $label, $description, $default, PARAM_INT));
}
}

0 comments on commit cae76db

Please sign in to comment.