From 9d6eb027b47b6fb1b50619d3d7e912fcedd2b338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Tue, 12 Feb 2013 19:02:30 +0100 Subject: [PATCH] MDL-34401 Cache the contents of version.php files This saves many inclusions of version.php files. --- lib/pluginlib.php | 38 +++++++++++++++++++++++++++--------- lib/tests/pluginlib_test.php | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index f56a5a519b3..109723939b2 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2170,15 +2170,28 @@ abstract class plugininfo_base { /** * Load the data from version.php. * + * @param bool $disablecache do not attempt to obtain data from the cache * @return stdClass the object called $plugin defined in version.php */ - protected function load_version_php() { + protected function load_version_php($disablecache=false) { + + $cache = cache::make('core', 'plugininfo_base'); + + $versionsphp = $cache->get('versions_php'); + + if (!$disablecache and $versionsphp !== false and isset($versionsphp[$this->component])) { + return $versionsphp[$this->component]; + } + $versionfile = $this->full_path('version.php'); $plugin = new stdClass(); if (is_readable($versionfile)) { include($versionfile); } + $versionsphp[$this->component] = $plugin; + $cache->set('versions_php', $versionsphp); + return $plugin; } @@ -2722,13 +2735,6 @@ class plugininfo_filter extends plugininfo_base { // do nothing, the name is set in self::get_plugins() } - /** - * @see load_version_php() - */ - protected function load_version_php() { - return parent::load_version_php(); - } - public function is_enabled() { $globalstates = self::get_global_states(); @@ -2876,9 +2882,20 @@ class plugininfo_mod extends plugininfo_base { /** * Load the data from version.php. + * + * @param bool $disablecache do not attempt to obtain data from the cache * @return object the data object defined in version.php. */ - protected function load_version_php() { + protected function load_version_php($disablecache=false) { + + $cache = cache::make('core', 'plugininfo_base'); + + $versionsphp = $cache->get('versions_php'); + + if (!$disablecache and $versionsphp !== false and isset($versionsphp[$this->component])) { + return $versionsphp[$this->component]; + } + $versionfile = $this->full_path('version.php'); $module = new stdClass(); @@ -2889,6 +2906,9 @@ class plugininfo_mod extends plugininfo_base { if (!isset($module->version) and isset($plugin->version)) { $module = $plugin; } + $versionsphp[$this->component] = $module; + $cache->set('versions_php', $versionsphp); + return $module; } diff --git a/lib/tests/pluginlib_test.php b/lib/tests/pluginlib_test.php index 1552d9369c7..141191386a3 100644 --- a/lib/tests/pluginlib_test.php +++ b/lib/tests/pluginlib_test.php @@ -338,7 +338,7 @@ class testable_plugininfo_mod extends plugininfo_mod { $this->versiondisk = 2012030500; } - protected function load_version_php() { + protected function load_version_php($disablecache=false) { return (object)array( 'version' => 2012030500, 'requires' => 2012010100,