From cae76dbc4d95508a5759c7fd3bae84625cd00d42 Mon Sep 17 00:00:00 2001 From: Julien Boulen Date: Fri, 5 Jul 2024 10:34:52 +0200 Subject: [PATCH] feat(settings): improve performance when we do not need the actual settings but only the administration pages structure --- settings.php | 83 ++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/settings.php b/settings.php index 3fe0a15..4d144b7 100644 --- a/settings.php +++ b/settings.php @@ -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)); + } }