Commit 16c2e48d9fd5a3d160d0c193e9a68935b73c829c
1 parent
e1c9c897
KTS-2386
"Add some basic plugin caching to improve performance" Updated. The original caching was causing problems. Had to revert caching to only around the database call. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7276 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
34 additions
and
38 deletions
lib/plugins/pluginutil.inc.php
| @@ -65,12 +65,18 @@ class KTPluginUtil { | @@ -65,12 +65,18 @@ class KTPluginUtil { | ||
| 65 | * Store the plugin cache in the cache directory. | 65 | * Store the plugin cache in the cache directory. |
| 66 | * | 66 | * |
| 67 | */ | 67 | */ |
| 68 | - static function savePluginCache() | 68 | + static function savePluginCache($array) |
| 69 | { | 69 | { |
| 70 | $config = KTConfig::getSingleton(); | 70 | $config = KTConfig::getSingleton(); |
| 71 | + $cachePlugins = $config->get('cache/cachePlugins', false); | ||
| 72 | + if (!$cachePlugins) | ||
| 73 | + { | ||
| 74 | + return false; | ||
| 75 | + } | ||
| 76 | + | ||
| 71 | $cacheDir = $config->get('cache/cacheDirectory'); | 77 | $cacheDir = $config->get('cache/cacheDirectory'); |
| 72 | 78 | ||
| 73 | - $written = file_put_contents($cacheDir . '/' . KTPluginUtil::CACHE_FILENAME , serialize($GLOBALS['_KT_PLUGIN'])); | 79 | + $written = file_put_contents($cacheDir . '/' . KTPluginUtil::CACHE_FILENAME , serialize($array)); |
| 74 | 80 | ||
| 75 | if (!$written) | 81 | if (!$written) |
| 76 | { | 82 | { |
| @@ -90,6 +96,11 @@ class KTPluginUtil { | @@ -90,6 +96,11 @@ class KTPluginUtil { | ||
| 90 | static function removePluginCache() | 96 | static function removePluginCache() |
| 91 | { | 97 | { |
| 92 | $config = KTConfig::getSingleton(); | 98 | $config = KTConfig::getSingleton(); |
| 99 | + $cachePlugins = $config->get('cache/cachePlugins', false); | ||
| 100 | + if (!$cachePlugins) | ||
| 101 | + { | ||
| 102 | + return false; | ||
| 103 | + } | ||
| 93 | $cacheDir = $config->get('cache/cacheDirectory'); | 104 | $cacheDir = $config->get('cache/cacheDirectory'); |
| 94 | 105 | ||
| 95 | $cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME; | 106 | $cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME; |
| @@ -104,6 +115,11 @@ class KTPluginUtil { | @@ -104,6 +115,11 @@ class KTPluginUtil { | ||
| 104 | static function readPluginCache() | 115 | static function readPluginCache() |
| 105 | { | 116 | { |
| 106 | $config = KTConfig::getSingleton(); | 117 | $config = KTConfig::getSingleton(); |
| 118 | + $cachePlugins = $config->get('cache/cachePlugins', false); | ||
| 119 | + if (!$cachePlugins) | ||
| 120 | + { | ||
| 121 | + return false; | ||
| 122 | + } | ||
| 107 | $cacheDir = $config->get('cache/cacheDirectory'); | 123 | $cacheDir = $config->get('cache/cacheDirectory'); |
| 108 | 124 | ||
| 109 | $cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME; | 125 | $cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME; |
| @@ -119,46 +135,27 @@ class KTPluginUtil { | @@ -119,46 +135,27 @@ class KTPluginUtil { | ||
| 119 | { | 135 | { |
| 120 | return false; | 136 | return false; |
| 121 | } | 137 | } |
| 122 | - return $cache; | 138 | + if (!class_exists('KTPluginEntityProxy')) { |
| 139 | + KTEntityUtil::_proxyCreate('KTPluginEntity', 'KTPluginEntityProxy'); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + return unserialize($cache); | ||
| 123 | } | 143 | } |
| 124 | 144 | ||
| 125 | static function loadPlugins () { | 145 | static function loadPlugins () { |
| 126 | 146 | ||
| 127 | - $cache = KTPluginUtil::readPluginCache(); | ||
| 128 | - if ($cache !== false) { | ||
| 129 | - require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | ||
| 130 | - require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php'); | ||
| 131 | - require_once(KT_LIB_DIR . '/actions/portletregistry.inc.php'); | ||
| 132 | - require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php'); | ||
| 133 | - require_once(KT_LIB_DIR . '/plugins/pageregistry.inc.php'); | ||
| 134 | - require_once(KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php'); | ||
| 135 | - require_once(KT_LIB_DIR . "/plugins/KTAdminNavigation.php"); | ||
| 136 | - require_once(KT_LIB_DIR . "/dashboard/dashletregistry.inc.php"); | ||
| 137 | - require_once(KT_LIB_DIR . "/i18n/i18nregistry.inc.php"); | ||
| 138 | - require_once(KT_LIB_DIR . "/help/help.inc.php"); | ||
| 139 | - require_once(KT_LIB_DIR . "/browse/columnregistry.inc.php"); | ||
| 140 | - require_once(KT_LIB_DIR . "/authentication/interceptorregistry.inc.php"); | ||
| 141 | - require_once(KT_LIB_DIR . "/widgets/widgetfactory.inc.php"); | ||
| 142 | - require_once(KT_LIB_DIR . "/validation/validatorfactory.inc.php"); | ||
| 143 | - | ||
| 144 | - // unserialize - step 1 - get _aPluginDetails so we can include all we need | ||
| 145 | - $GLOBALS['_KT_PLUGIN'] = unserialize($cache); | ||
| 146 | - | ||
| 147 | - foreach($GLOBALS['_KT_PLUGIN']['oKTPluginRegistry']->_aPluginDetails as $detail) | ||
| 148 | - { | ||
| 149 | - $classname = $detail[0]; | ||
| 150 | - $inc = $detail[2]; | ||
| 151 | - if (!class_exists($classname)) | ||
| 152 | - { | ||
| 153 | - require_once($inc); | ||
| 154 | - } | ||
| 155 | - } | ||
| 156 | - // unserialize - step 2 - so we don't have incomplete classes | ||
| 157 | - $GLOBALS['_KT_PLUGIN'] = unserialize($cache); | ||
| 158 | - return; | ||
| 159 | - } | ||
| 160 | $GLOBALS['_KT_PLUGIN'] = array(); | 147 | $GLOBALS['_KT_PLUGIN'] = array(); |
| 161 | - $aPlugins = KTPluginEntity::getList("disabled=0"); | 148 | + $cache = KTPluginUtil::readPluginCache(); |
| 149 | + if ($cache === false) | ||
| 150 | + { | ||
| 151 | + $aPlugins = KTPluginEntity::getList("disabled=0"); | ||
| 152 | + KTPluginUtil::savePluginCache($aPlugins); | ||
| 153 | + } | ||
| 154 | + else | ||
| 155 | + { | ||
| 156 | + $aPlugins = $cache; | ||
| 157 | + } | ||
| 158 | + | ||
| 162 | if (count($aPlugins) === 0) { | 159 | if (count($aPlugins) === 0) { |
| 163 | KTPluginUtil::registerPlugins(); | 160 | KTPluginUtil::registerPlugins(); |
| 164 | } | 161 | } |
| @@ -198,7 +195,6 @@ class KTPluginUtil { | @@ -198,7 +195,6 @@ class KTPluginUtil { | ||
| 198 | $oPlugin->load(); | 195 | $oPlugin->load(); |
| 199 | } | 196 | } |
| 200 | } | 197 | } |
| 201 | - KTPluginUtil::savePluginCache(); | ||
| 202 | } | 198 | } |
| 203 | 199 | ||
| 204 | /** | 200 | /** |