From 8a7b405ec86c2f0670435547acb497b9583d481c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 26 Aug 2009 05:04:58 +0000 Subject: [PATCH] Caching of filters added (should work now) --- .gitattributes | 1 + inc/extensions/ext-cache.php | 15 +++- inc/filters.php | 76 ++++++++++++------- inc/language/cache_de.php | 1 + inc/libs/cache_functions.php | 14 +++- inc/load_cache.php | 12 ++- inc/load_extensions.php | 13 ++-- inc/loader/load_cache-config.php | 2 +- inc/loader/load_cache-filter.php | 75 ++++++++++++++++++ inc/modules/admin/overview-inc.php | 11 ++- inc/modules/admin/what-config_cache.php | 16 ++++ .../de/html/admin/admin_config_cache.tpl | 11 +++ 12 files changed, 199 insertions(+), 48 deletions(-) create mode 100644 inc/loader/load_cache-filter.php diff --git a/.gitattributes b/.gitattributes index 4b456d2c6e..113ad4023c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -274,6 +274,7 @@ inc/load_extensions.php -text inc/loader/.htaccess -text inc/loader/load_cache-admin.php -text inc/loader/load_cache-config.php -text +inc/loader/load_cache-filter.php -text inc/loader/load_cache-modreg.php -text inc/loader/load_cache-refdepths.php -text inc/loader/load_cache-refsystem.php -text diff --git a/inc/extensions/ext-cache.php b/inc/extensions/ext-cache.php index 171752500a..8f384d5861 100644 --- a/inc/extensions/ext-cache.php +++ b/inc/extensions/ext-cache.php @@ -44,10 +44,10 @@ if (!defined('__SECURITY')) { } // Version number -EXT_SET_VERSION('0.2.2'); +EXT_SET_VERSION('0.2.3'); // Version history array (add more with , '0.1.0' and so on) -EXT_SET_VER_HISTORY(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2')); +EXT_SET_VER_HISTORY(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3')); // Which load mode? switch ($EXT_LOAD_MODE) { @@ -74,6 +74,7 @@ switch ($EXT_LOAD_MODE) { unregisterFilter('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run); unregisterFilter('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run); unregisterFilter('extension_remove', 'CACHE_DESTROY_ALL', true, $dry_run); + unregisterFilter('shutdown', 'CACHE_DESTROY_FILTER', true, $dry_run); break; case 'activate': // Do stuff when admin activates this extension @@ -237,6 +238,16 @@ switch ($EXT_LOAD_MODE) { // Update notes (these will be set as task text!) EXT_SET_UPDATE_NOTES("Weitere Filter hinzugefügt."); break; + + case '0.2.3': // SQL queries for v0.2.3 + ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_filter ENUM('Y','N') NOT NULL DEFAULT 'Y'"); + + // Update notes (these will be set as task text!) + EXT_SET_UPDATE_NOTES("Cachen von Filtern hinzugefügt."); + + // Register a new filter + registerFilter('shutdown', 'CACHE_DESTROY_FILTER', false, true, $dry_run); + break; } break; diff --git a/inc/filters.php b/inc/filters.php index 433f495809..39d86d19f1 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -47,8 +47,7 @@ function initFilterSystem () { // Is the filter already initialized? if ((isset($GLOBALS['filters']['chains'])) && (is_array($GLOBALS['filters']['chains']))) { // Then abort here - addFatalMessage(__FUNCTION__, __LINE__, getMessage('FILTER_FAILED_ALREADY_INIT')); - return false; + debug_report_bug(getMessage('FILTER_FAILED_ALREADY_INIT')); } // END - if // Init the filter system (just some ideas) @@ -63,7 +62,26 @@ function initFilterSystem () { $GLOBALS['filters']['counter'] = array(); // Load all saved filers if sql_patches is updated - if (GET_EXT_VERSION('sql_patches') >= '0.5.9') { + if (isset($GLOBALS['cache_array']['filter'])) { + // Found in cache so rewrite the array + $filterArray = array(); + foreach ($GLOBALS['cache_array']['filter']['filter_name'] as $idx => $filterName) { + // Get filter function + $filterFunction = $GLOBALS['cache_array']['filter']['filter_function'][$idx]; + + // Add the element with mapped index + $filterArray['counter'][$filterName][$filterFunction] = $GLOBALS['cache_array']['filter']['filter_counter'][$idx]; + $filterArray['loaded'][$filterName][$filterFunction] = true; + $filterArray['chains'][$filterName][$filterFunction] = $GLOBALS['cache_array']['filter']['filter_active'][$idx]; + } // END - foreach + + // Set the array + //die('
'.print_r($filterArray, true).'
'); + $GLOBALS['filters'] = $filterArray; + + // Remove the cache + unset($GLOBALS['cache_array']['filter']); + } elseif (GET_EXT_VERSION('sql_patches') >= '0.5.9') { // Init add $add = ''; if (GET_EXT_VERSION('sql_patches') >= '0.6.0') $add = ", `filter_counter`"; @@ -100,38 +118,38 @@ ORDER BY `filter_id` ASC", __FUNCTION__, __LINE__); // Free result SQL_FREERESULT($result); - } // END - if - // Init filters - registerFilter('init', 'UPDATE_LOGIN_DATA'); - registerFilter('init', 'INIT_RANDOMIZER'); + // Init filters + registerFilter('init', 'UPDATE_LOGIN_DATA'); + registerFilter('init', 'INIT_RANDOMIZER'); - // Login failures handler - registerFilter('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES'); + // Login failures handler + registerFilter('post_youhere_line', 'CALL_HANDLER_LOGIN_FAILTURES'); - // Filters for pre-extension-registration - registerFilter('pre_extension_installed', 'RUN_SQLS'); + // Filters for pre-extension-registration + registerFilter('pre_extension_installed', 'RUN_SQLS'); - // Filters for post-extension-registration - registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION'); - registerFilter('post_extension_installed', 'SOLVE_TASK'); - registerFilter('post_extension_installed', 'LOAD_INCLUDES'); - registerFilter('post_extension_installed', 'REMOVE_UPDATES'); + // Filters for post-extension-registration + registerFilter('post_extension_installed', 'AUTO_ACTIVATE_EXTENSION'); + registerFilter('post_extension_installed', 'SOLVE_TASK'); + registerFilter('post_extension_installed', 'LOAD_INCLUDES'); + registerFilter('post_extension_installed', 'REMOVE_UPDATES'); - // Solving tasks - registerFilter('solve_task', 'SOLVE_TASK'); + // Solving tasks + registerFilter('solve_task', 'SOLVE_TASK'); - // Loading includes in general - registerFilter('load_includes', 'LOAD_INCLUDES'); + // Loading includes in general + registerFilter('load_includes', 'LOAD_INCLUDES'); - // Run SQLs - registerFilter('run_sqls', 'RUN_SQLS'); + // Run SQLs + registerFilter('run_sqls', 'RUN_SQLS'); - // Admin ACL check - registerFilter('check_admin_acl', 'CHECK_ADMIN_ACL'); + // Admin ACL check + registerFilter('check_admin_acl', 'CHECK_ADMIN_ACL'); - // Register shutdown filters - registerFilter('shutdown', 'FLUSH_FILTERS'); + // Register shutdown filters + registerFilter('shutdown', 'FLUSH_FILTERS'); + } // END - if } // "Registers" a new filter function @@ -319,9 +337,9 @@ function FILTER_FLUSH_FILTERS () { foreach ($filterArray as $filterFunction => $cnt) { // Construct and add the query ADD_SQL(sprintf("UPDATE `{!_MYSQL_PREFIX!}_filters` SET `filter_counter`=%s WHERE `filter_name`='%s' AND `filter_function`='%s' LIMIT 1", - bigintval($cnt), - $filterName, - $filterFunction + bigintval($cnt), + $filterName, + $filterFunction )); } // END - foreach } // END - foreach diff --git a/inc/language/cache_de.php b/inc/language/cache_de.php index d6aa3531ca..a9e3ca55fc 100644 --- a/inc/language/cache_de.php +++ b/inc/language/cache_de.php @@ -65,6 +65,7 @@ define('ADMIN_CACHE_CONFIG', "Soll der Zugriff auf die Tabelle {!_MYSQL_ define('ADMIN_CACHE_MODREG', "Soll der Zugriff auf die Tabelle {!_MYSQL_PREFIX!}_mod_reg beschleunigt werden?"); define('ADMIN_CACHE_REFDEPTH', "Soll der Zugriff auf die Tabelle {!_MYSQL_PREFIX!}_refdepths beschleunigt werden?"); define('ADMIN_CACHE_REFSYS', "Soll der Zugriff auf die Tabelle {!_MYSQL_PREFIX!}_refsystem beschleunigt werden?"); +define('ADMIN_CACHE_filter', "Soll der Zugriff auf die Tabelle {!_MYSQL_PREFIX!}_filter beschleunigt werden?"); define('ADMIN_CACHE_THEMES', "Soll der Zugriff auf die Tabelle {!_MYSQL_PREFIX!}_themes beschleunigt werden?"); define('ADMIN_CACHE_ADMIN_MENU', "Soll der Aufbau des Administratormenüs beschleunigt werden (EXPERIMENTELL!)?"); define('ADMIN_CACHE_PATH', "Relativer Pfad für alle Cache-Dateien zum Pfad inc"); diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php index 17910c97cd..a34313d1eb 100644 --- a/inc/libs/cache_functions.php +++ b/inc/libs/cache_functions.php @@ -477,7 +477,7 @@ function FILTER_CACHE_DESTROY_ON_ADMIN_CHANGE () { // Destroy all cache files function FILTER_CACHE_DESTROY_ALL () { // Skip this step if the cache instance is not there - DEBUG_LOG(__FUNCTION__, __LINE__, 'Called!'); + //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Called!'); if (!isCacheInstanceValid()) return false; // Remove cache files @@ -490,7 +490,17 @@ function FILTER_CACHE_DESTROY_ALL () { if ($GLOBALS['cache_instance']->loadCacheFile('refsystem')) $GLOBALS['cache_instance']->destroyCacheFile(false); if ($GLOBALS['cache_instance']->loadCacheFile('themes')) $GLOBALS['cache_instance']->destroyCacheFile(false); if ($GLOBALS['cache_instance']->loadCacheFile('revision')) $GLOBALS['cache_instance']->destroyCacheFile(false); - DEBUG_LOG(__FUNCTION__, __LINE__, 'Done!'); + if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->destroyCacheFile(false); + //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Done!'); +} + +// Filter for purging 'filter' cache +function FILTER_CACHE_DESTROY_FILTER () { + // Skip this step if the cache instance is not there + if ((!isCacheInstanceValid()) || (getConfig('update_filter_usage') == 'N')) return false; + + // Remove cache files + if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->destroyCacheFile(false); } // Filter for purging entire admin menu cache diff --git a/inc/load_cache.php b/inc/load_cache.php index ffe91d926e..2a6dc159d5 100644 --- a/inc/load_cache.php +++ b/inc/load_cache.php @@ -46,8 +46,16 @@ if (!defined('__SECURITY')) { INIT_INC_POOL(); SET_INC_POOL(getArrayFromDirectory('inc/loader/', 'load_cache-')); -// Run the filter -runFilterChain('load_includes'); +// Pre-load filter cacher +loadIncludeOnce('inc/loader/load_cache-filter.php'); + +// Init filter system here +initFilterSystem(); + +// We have to include all here by-hand +foreach (GET_INC_POOL() as $inc) { + loadIncludeOnce($inc); +} // END - foreach // ?> diff --git a/inc/load_extensions.php b/inc/load_extensions.php index 731bbd4bf9..d5c3130456 100644 --- a/inc/load_extensions.php +++ b/inc/load_extensions.php @@ -159,7 +159,7 @@ if ($GLOBALS['cache_mode'] == 'load') { $EXT_DUMMY['ext_deprecated'][$name] = 'N'; // Mark it as active extension - $GLOBALS['cache_array']['active_extensions']['$name'] = $EXT_DUMMY['ext_keep'][$k]; + $GLOBALS['cache_array']['active_extensions'][$name] = $EXT_DUMMY['ext_keep'][$k]; unset($EXT_DUMMY['ext_keep'][$k]); // Remove unneccessary data from memory @@ -184,9 +184,6 @@ if ($GLOBALS['cache_mode'] == 'load') { LOAD_EXTENSION($ext); } // END - foreach - // Init filter system - initFilterSystem(); - // Load more cache files (like admins) loadIncludeOnce('inc/load_cache.php'); @@ -274,16 +271,16 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && ((($GLOBALS['cache_mode'] == 'init') && ( } } // END - while - // Init filter system - initFilterSystem(); - if ($GLOBALS['cache_mode'] == 'init') { // Close cache file $GLOBALS['cache_instance']->finalize(); // Load more cache files (like admins) loadIncludeOnce('inc/load_cache.php'); - } // END - if + } else { + // Init filter system for non-init mode + initFilterSystem(); + } // Free memory SQL_FREERESULT($res_ext_crt); diff --git a/inc/loader/load_cache-config.php b/inc/loader/load_cache-config.php index b0e9f29117..8f7e4a7e7b 100644 --- a/inc/loader/load_cache-config.php +++ b/inc/loader/load_cache-config.php @@ -52,7 +52,7 @@ if (($GLOBALS['cache_instance']->loadCacheFile('config', true)) && ($GLOBALS['ca $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches'); // Load all modules and their data - $result = SQL_QUERY('SELECT * FROM `{!_MYSQL_PREFIX!}_config` ORDER BY config ASC', __FILE__, __LINE__); + $result = SQL_QUERY('SELECT * FROM `{!_MYSQL_PREFIX!}_config` ORDER BY `config` ASC', __FILE__, __LINE__); while ($data = SQL_FETCHARRAY($result)) { // Add row to cache file $GLOBALS['cache_instance']->addRow($data); diff --git a/inc/loader/load_cache-filter.php b/inc/loader/load_cache-filter.php new file mode 100644 index 0000000000..de3c9322a5 --- /dev/null +++ b/inc/loader/load_cache-filter.php @@ -0,0 +1,75 @@ +loadCacheFile('filter', true)) && ($GLOBALS['cache_instance']->extensionVersionMatches('sql_patches'))) { + // Load filter from cache + $GLOBALS['cache_array']['filter'] = $GLOBALS['cache_instance']->getArrayFromCache(); +} elseif ((getConfig('cache_filter') == 'Y') && (getOutputMode() != '1') && (getOutputMode() != '-1')) { + // Create cache file here + $GLOBALS['cache_instance']->init('FILTER'); + $GLOBALS['cache_instance']->storeExtensionVersion('sql_patches'); + + // Load all modules and their data + $result = SQL_QUERY('SELECT * FROM `{!_MYSQL_PREFIX!}_filters` ORDER BY `filter_name` ASC', __FILE__, __LINE__); + while ($data = SQL_FETCHARRAY($result)) { + // Add row to cache file + $GLOBALS['cache_instance']->addRow($data); + } // END - while + + // Free memory + SQL_FREERESULT($result); + + // Close the cache + $GLOBALS['cache_instance']->finalize(); + + // Include loader again + require(__FILE__); +} + +// +?> diff --git a/inc/modules/admin/overview-inc.php b/inc/modules/admin/overview-inc.php index 4675398ce0..e553173092 100644 --- a/inc/modules/admin/overview-inc.php +++ b/inc/modules/admin/overview-inc.php @@ -45,18 +45,20 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) { function OUTPUT_STANDARD_OVERVIEW (&$result_tasks) { // First check for solved and not assigned tasks and assign them to current admin SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET `assigned_admin`=%s WHERE assigned_admin < 1 AND status != 'NEW'", - array(getCurrentAdminId()), __FILE__, __LINE__); + array(getCurrentAdminId()), __FILE__, __LINE__); // We currently don't want to install an extension so let's find out if we need... $EXT_LOAD_MODE = 'register'; $jobsDone = true; // Open the extension directory - $extensionList = getArrayFromDirectory("inc/extensions/", "ext-", false, false); + $extensionList = getArrayFromDirectory('inc/extensions/', 'ext-', false, false); foreach ($extensionList as $file) { + // Only file name is required... :( + $file = basename($file); + // Is this file an extension? - if ((substr($file, 0, 4) == "ext-") && (substr($file, -4) == '.php')) { - //* DEBUG: */ echo $file."
\n"; + if ((substr($file, 0, 4) == 'ext-') && (substr($file, -4) == '.php')) { // Possible newly installed extension found so we extract extension's name $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!! @@ -65,6 +67,7 @@ function OUTPUT_STANDARD_OVERVIEW (&$result_tasks) { // Check if extension is installed or not $ext_ver = GET_EXT_VERSION($ext_name); + //* DEBUG: */ echo $ext_name."=".$ext_ver."
\n"; // Is the extension not yet installed? if (empty($ext_ver)) { diff --git a/inc/modules/admin/what-config_cache.php b/inc/modules/admin/what-config_cache.php index 59ac1df1d0..28b2d7e786 100644 --- a/inc/modules/admin/what-config_cache.php +++ b/inc/modules/admin/what-config_cache.php @@ -83,6 +83,10 @@ if (isFormSent()) { $GLOBALS['cache_instance']->destroyCacheFile(); } // END - if + if ((REQUEST_POST('cache_filter') == 'N') && ($GLOBALS['cache_instance']->loadCacheFile('filter'))) { + $GLOBALS['cache_instance']->destroyCacheFile(); + } // END - if + // Save configuration ADMIN_SAVE_SETTINGS_POST(); } else { @@ -172,6 +176,18 @@ if (isFormSent()) { break; } // END - switch + switch (getConfig('cache_filter')) { + case 'Y': + define('__FILTER_Y', ' checked="checked"'); + define('__FILTER_N', ''); + break; + + case 'N': + define('__FILTER_Y', ''); + define('__FILTER_N', ' checked="checked"'); + break; + } // END - switch + switch (getConfig('cache_themes')) { case 'Y': define('__THEMES_Y', ' checked="checked"'); diff --git a/templates/de/html/admin/admin_config_cache.tpl b/templates/de/html/admin/admin_config_cache.tpl index 478af6bd50..4d1dca9b94 100644 --- a/templates/de/html/admin/admin_config_cache.tpl +++ b/templates/de/html/admin/admin_config_cache.tpl @@ -84,6 +84,17 @@   + + + {--ADMIN_CACHE_FILTER--} +  {--YES--} +  {--NO--}  + + + +   + {--ADMIN_CACHE_THEMES--} -- 2.39.5