MDL-49329 admin: Do not always load info about available updates
Before this patch, whenever core_plugin_manager::get_plugins() was called, it always attached info about available updates. But this is needed only in quite rare cases, such as when the admin is looking at the Plugins overview and Plugins check screens. There is no need to load this on other places and for non-admin users. The patch removes the loading from the method core_plugin_manager::get_plugins_of_type() and implements lazy loading directly in the plugininfo classes so that it is loaded only when \core\plugininfo\base::available_updates() is actually called.
This commit is contained in:
+6
-7
@@ -597,14 +597,13 @@ if ($updateschecker->enabled()) {
|
||||
$pluginman = core_plugin_manager::instance();
|
||||
foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) {
|
||||
foreach ($plugintypeinstances as $pluginname => $plugininfo) {
|
||||
if (!empty($plugininfo->availableupdates)) {
|
||||
foreach ($plugininfo->availableupdates as $pluginavailableupdate) {
|
||||
if ($pluginavailableupdate->version > $plugininfo->versiondisk) {
|
||||
if (!isset($availableupdates[$plugintype.'_'.$pluginname])) {
|
||||
$availableupdates[$plugintype.'_'.$pluginname] = array();
|
||||
}
|
||||
$availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate;
|
||||
$pluginavailableupdates = $plugininfo->available_updates();
|
||||
if (!empty($pluginavailableupdates)) {
|
||||
foreach ($pluginavailableupdates as $pluginavailableupdate) {
|
||||
if (!isset($availableupdates[$plugintype.'_'.$pluginname])) {
|
||||
$availableupdates[$plugintype.'_'.$pluginname] = array();
|
||||
}
|
||||
$availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -1202,11 +1202,10 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
$updateable = array();
|
||||
foreach ($plugininfo as $plugintype => $pluginnames) {
|
||||
foreach ($pluginnames as $pluginname => $pluginfo) {
|
||||
if (!empty($pluginfo->availableupdates)) {
|
||||
foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
|
||||
if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
|
||||
$updateable[$plugintype][$pluginname] = $pluginfo;
|
||||
}
|
||||
$pluginavailableupdates = $pluginfo->available_updates();
|
||||
if (!empty($pluginavailableupdates)) {
|
||||
foreach ($pluginavailableupdates as $pluginavailableupdate) {
|
||||
$updateable[$plugintype][$pluginname] = $pluginfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,14 +384,6 @@ class core_plugin_manager {
|
||||
$plugins = $plugintypeclass::get_plugins($type, $types[$type], $plugintypeclass);
|
||||
$this->pluginsinfo[$type] = $plugins;
|
||||
|
||||
if (empty($CFG->disableupdatenotifications) and !during_initial_install()) {
|
||||
// Append the information about available updates provided by {@link \core\update\checker()}.
|
||||
$provider = \core\update\checker::instance();
|
||||
foreach ($plugins as $plugininfoholder) {
|
||||
$plugininfoholder->check_available_updates($provider);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->pluginsinfo[$type];
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,9 @@ abstract class base {
|
||||
public $instances;
|
||||
/** @var int order of the plugin among other plugins of the same type - not supported yet */
|
||||
public $sortorder;
|
||||
|
||||
/** @var array|null array of {@link \core\update\info} for this plugin */
|
||||
public $availableupdates;
|
||||
protected $availableupdates;
|
||||
|
||||
/**
|
||||
* Finds all enabled plugins, the result may include missing plugins.
|
||||
@@ -394,18 +395,25 @@ abstract class base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the property {@link $availableupdates} with the information provided by
|
||||
* available update checker
|
||||
* Populates the property {@link $availableupdates}
|
||||
*
|
||||
* @param \core\update\checker $provider the class providing the available update info
|
||||
* This is supposed to be called by {@link self::available_updates()} only
|
||||
* to lazy load the data once they are first requested.
|
||||
*/
|
||||
public function check_available_updates(\core\update\checker $provider) {
|
||||
protected function load_available_updates() {
|
||||
global $CFG;
|
||||
|
||||
$provider = \core\update\checker::instance();
|
||||
|
||||
if (!$provider->enabled() or during_initial_install()) {
|
||||
$this->availableupdates = array();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($CFG->updateminmaturity)) {
|
||||
$minmaturity = $CFG->updateminmaturity;
|
||||
} else {
|
||||
// This can happen during the very first upgrade to 2.3 .
|
||||
// This can happen during the very first upgrade to 2.3.
|
||||
$minmaturity = MATURITY_STABLE;
|
||||
}
|
||||
|
||||
@@ -424,6 +432,11 @@ abstract class base {
|
||||
*/
|
||||
public function available_updates() {
|
||||
|
||||
if ($this->availableupdates === null) {
|
||||
// Lazy load the information about available updates.
|
||||
$this->load_available_updates();
|
||||
}
|
||||
|
||||
if (empty($this->availableupdates) or !is_array($this->availableupdates)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user