aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-03-03 11:18:09 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-03-03 11:18:09 +0000
commit52b6fde352fd0282a8a3ddfc3f2ff218d97f7dbb (patch)
tree6a0499f00af2f806ab5a0b17b0714063b90c1652 /engine
parent106050295f1363b94d69eda97e6cfb611b66a65e (diff)
downloadelgg-52b6fde352fd0282a8a3ddfc3f2ff218d97f7dbb.tar.gz
elgg-52b6fde352fd0282a8a3ddfc3f2ff218d97f7dbb.tar.bz2
Closes #831: Plugin view location is now cached in a file in dataroot and is invalidated on upgrade and plugin enable/disable/reorder. This means that views no longer have to be discovered on boot - reducing file IO from crazy amounts to 1. This also helps make adding new plugins a linear event.
git-svn-id: https://code.elgg.org/elgg/trunk@3025 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/elgglib.php15
-rw-r--r--engine/lib/plugins.php49
2 files changed, 50 insertions, 14 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 1b2629a22..5571339cd 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -496,6 +496,21 @@
}
/**
+ * This is a factory function which produces an ElggCache object suitable for caching file load paths.
+ *
+ * TODO: Can this be done in a cleaner way?
+ * TODO: Swap to memcache etc?
+ */
+ function elgg_get_filepath_cache()
+ {
+ global $CONFIG;
+ static $FILE_PATH_CACHE;
+ if (!$FILE_PATH_CACHE) $FILE_PATH_CACHE = new ElggFileCache($CONFIG->dataroot);
+
+ return $FILE_PATH_CACHE;
+ }
+
+ /**
* Internal function for retrieving views used by elgg_view_tree
*
* @param unknown_type $dir
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index 937766e66..c70cd8ebc 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -210,10 +210,21 @@
* @package Elgg
* @subpackage Core
*/
- function load_plugins() {
-
- global $CONFIG;
- if (!empty($CONFIG->pluginspath)) {
+ function load_plugins() {
+
+ global $CONFIG;
+
+ $cache = elgg_get_filepath_cache();
+
+ if (!empty($CONFIG->pluginspath)) {
+
+ // See if we have cached values for things
+ $cached_view_paths = $cache->load('view_paths');
+ if ($cached_view_paths) $CONFIG->views = unserialize($cached_view_paths);
+
+ $cached_lang_paths = $cache->load('lang_paths');
+ if ($cached_lang_paths) $CONFIG->views = unserialize($cached_lang_paths);
+
// temporary disable all plugins if there is a file called 'disabled' in the plugin dir
if (file_exists($CONFIG->pluginspath . "disabled"))
@@ -221,28 +232,38 @@
$plugins = get_plugin_list();
- if (sizeof($plugins))
+ if (sizeof($plugins))
+ {
foreach($plugins as $mod) {
if (is_plugin_enabled($mod)) {
if (file_exists($CONFIG->pluginspath . $mod)) {
if (!include($CONFIG->pluginspath . $mod . "/start.php"))
- throw new PluginException(sprintf(elgg_echo('PluginException:MisconfiguredPlugin'), $mod));
- if (is_dir($CONFIG->pluginspath . $mod . "/views")) {
- if ($handle = opendir($CONFIG->pluginspath . $mod . "/views")) {
- while ($viewtype = readdir($handle)) {
- if (!in_array($viewtype,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . $mod . "/views/" . $viewtype)) {
- autoregister_views("",$CONFIG->pluginspath . $mod . "/views/" . $viewtype,$CONFIG->pluginspath . $mod . "/views/", $viewtype);
+ throw new PluginException(sprintf(elgg_echo('PluginException:MisconfiguredPlugin'), $mod));
+
+ if (!$cached_view_paths)
+ {
+ if (is_dir($CONFIG->pluginspath . $mod . "/views")) {
+ if ($handle = opendir($CONFIG->pluginspath . $mod . "/views")) {
+ while ($viewtype = readdir($handle)) {
+ if (!in_array($viewtype,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . $mod . "/views/" . $viewtype)) {
+ autoregister_views("",$CONFIG->pluginspath . $mod . "/views/" . $viewtype,$CONFIG->pluginspath . $mod . "/views/", $viewtype);
+ }
}
}
- }
- }
+ }
+ }
+
if (is_dir($CONFIG->pluginspath . $mod . "/languages")) {
register_translations($CONFIG->pluginspath . $mod . "/languages/");
}
}
}
}
-
+ }
+
+ // Cache results
+ if (!$cached_view_paths)
+ $cache->save('view_paths', serialize($CONFIG->views));
}
}