mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 03:16:42 +02:00
MDL-39445 get_plugin_list clean_param use is slow
get_plugin_list was calling clean_param($pluginname, PARAM_PLUGIN) a lot (600+ times per page), and that is much slower than you would guess. A specific function for this case, (which we then also use from clean_param) is a performance win.
This commit is contained in:
parent
95190fda69
commit
5f85073525
3 changed files with 28 additions and 9 deletions
|
@ -912,10 +912,7 @@ function clean_param($param, $type) {
|
|||
case PARAM_PLUGIN:
|
||||
case PARAM_AREA:
|
||||
// we do not want any guessing here, either the name is correct or not
|
||||
if (!preg_match('/^[a-z][a-z0-9_]*[a-z0-9]$/', $param)) {
|
||||
return '';
|
||||
}
|
||||
if (strpos($param, '__') !== false) {
|
||||
if (!is_valid_plugin_name($param)) {
|
||||
return '';
|
||||
}
|
||||
return $param;
|
||||
|
@ -8286,6 +8283,15 @@ function get_plugin_types($fullpaths=true) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method validates a plug name. It is much faster than calling clean_param.
|
||||
* @param string $name a string that might be a plugin name.
|
||||
* @return bool if this string is a valid plugin name.
|
||||
*/
|
||||
function is_valid_plugin_name($name) {
|
||||
return (bool) preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]$/', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplified version of get_list_of_plugins()
|
||||
* @param string $plugintype type of plugin
|
||||
|
@ -8358,9 +8364,8 @@ function get_plugin_list($plugintype) {
|
|||
if (in_array($pluginname, $ignored)) {
|
||||
continue;
|
||||
}
|
||||
$pluginname = clean_param($pluginname, PARAM_PLUGIN);
|
||||
if (empty($pluginname)) {
|
||||
// better ignore plugins with problematic names here
|
||||
if (!is_valid_plugin_name($pluginname)) {
|
||||
// Better ignore plugins with problematic names here.
|
||||
continue;
|
||||
}
|
||||
$result[$pluginname] = $fulldir.'/'.$pluginname;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue