From 30fccfcd8240e1c48edbf21dc1219e492a606a4c Mon Sep 17 00:00:00 2001 From: Skylar Kelty Date: Thu, 13 Apr 2017 10:36:05 +0100 Subject: [PATCH] MDL-58590 mobile: Cache mobile-supporting plugins --- admin/tool/mobile/classes/api.php | 12 +++++++- admin/tool/mobile/db/caches.php | 34 +++++++++++++++++++++++ admin/tool/mobile/lang/en/tool_mobile.php | 1 + admin/tool/mobile/version.php | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 admin/tool/mobile/db/caches.php diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index 1545996f252b4..f61f8b52c3ab1 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -58,6 +58,13 @@ public static function get_plugins_supporting_mobile() { global $CFG; require_once($CFG->libdir . '/adminlib.php'); + // Check if we can return this from cache. + $cache = \cache::make('tool_mobile', 'plugininfo'); + $pluginsinfo = $cache->get('mobileplugins'); + if ($pluginsinfo !== false) { + return (array)$pluginsinfo; + } + $pluginsinfo = []; $plugintypes = core_component::get_plugin_types(); @@ -69,7 +76,7 @@ public static function get_plugins_supporting_mobile() { $component = $plugintype . '_' . $plugin; $version = get_component_version($component); - require_once("$path/db/mobile.php"); + require("$path/db/mobile.php"); foreach ($addons as $addonname => $addoninfo) { $plugininfo = array( 'component' => $component, @@ -92,6 +99,9 @@ public static function get_plugins_supporting_mobile() { } } } + + $cache->set('mobileplugins', $pluginsinfo); + return $pluginsinfo; } diff --git a/admin/tool/mobile/db/caches.php b/admin/tool/mobile/db/caches.php new file mode 100644 index 0000000000000..6cfcca7805132 --- /dev/null +++ b/admin/tool/mobile/db/caches.php @@ -0,0 +1,34 @@ +. + +/** + * Mobile cache definitions. + * + * @package tool_mobile + * @copyright 2017 Skylar Kelty + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +$definitions = array( + 'plugininfo' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'staticacceleration' => true, + 'staticaccelerationsize' => 1 + ) +); diff --git a/admin/tool/mobile/lang/en/tool_mobile.php b/admin/tool/mobile/lang/en/tool_mobile.php index 1818a2f405ea0..56e929a4bdecd 100644 --- a/admin/tool/mobile/lang/en/tool_mobile.php +++ b/admin/tool/mobile/lang/en/tool_mobile.php @@ -26,6 +26,7 @@ $string['androidappid_desc'] = 'This setting may be left as default unless you have a custom Android app.'; $string['autologinkeygenerationlockout'] = 'Auto-login key generation is blocked because of too many requests within an hour.'; $string['autologinnotallowedtoadmins'] = 'Auto-login is not allowed for site admins.'; +$string['cachedef_plugininfo'] = 'This stores the list of plugins with mobile addons'; $string['clickheretolaunchtheapp'] = 'Click here if the app does not open automatically.'; $string['configmobilecssurl'] = 'A CSS file to customise your mobile app interface.'; $string['customlangstrings'] = 'Custom language strings'; diff --git a/admin/tool/mobile/version.php b/admin/tool/mobile/version.php index 4632c5d72a950..d42f1213b9207 100644 --- a/admin/tool/mobile/version.php +++ b/admin/tool/mobile/version.php @@ -23,7 +23,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016120505; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2017041200; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2016112900; // Requires this Moodle version. $plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics). $plugin->dependencies = array(