From efe6057fdb1c02a518172e985298e66accef90d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 9 Sep 2008 18:03:21 +0000 Subject: [PATCH] Heavy improvements to caching system. Now, if cache is installed the system relays more on it. --- inc/db/lib-mysql3.php | 19 ++++--- inc/extensions.php | 38 +++++++------- inc/modules/admin/overview-inc.php | 51 +++++-------------- inc/mysql-manager.php | 79 ++++++++++++++++++++++++++---- 4 files changed, 111 insertions(+), 76 deletions(-) diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index f8eceec4b3..14fa713b84 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -4,11 +4,11 @@ * =============== Last change: 08/29/2004 * * * * -------------------------------------------------------------------- * - * File : lib.php * + * File : lib-mysql3.php * * -------------------------------------------------------------------- * - * Short description : * + * Short description : Database layer for MySQL +3.x server * * -------------------------------------------------------------------- * - * Kurzbeschreibung : * + * Kurzbeschreibung : Datenbankschicht fuer MySQL +3.x Server * * -------------------------------------------------------------------- * * * * -------------------------------------------------------------------- * @@ -48,6 +48,7 @@ function SQL_QUERY($sql_string, $F, $L) { $querytimeBefore = array_sum(explode(' ', microtime())); // Run SQL command + //* DEBUG: */ echo $sql_string."
\n"; $result = @mysql_query($sql_string, $link) or ADD_FATAL($F." (".$L."):".mysql_error()."
".MYSQL_QUERY_STRING."
@@ -203,6 +204,7 @@ function SQL_FREERESULT($result) { // SQL string escaping function SQL_QUERY_ESC($qstring, $data, $file, $line, $run=true, $strip=true) { global $link; + $query = ""; $eval = "\$query = sprintf(\"".$qstring."\""; foreach ($data as $var) { if ((!empty($var)) || ($var === 0)) { @@ -219,10 +221,15 @@ function SQL_QUERY_ESC($qstring, $data, $file, $line, $run=true, $strip=true) { // // Debugging // - //$fp = fopen(PATH."escape_debug.log", 'a') or mxchange_die("Cannot write debug.log!"); - //fwrite($fp, $file."(".$line."): ".str_replace('\r', "", str_replace('\n', " ", $eval))."\n"); + //$fp = fopen(PATH."inc/cache/escape_debug.log", 'a') or mxchange_die("Cannot write debug.log!"); + //fwrite($fp, $file."(".$line."): ".str_replace("\r", "", str_replace("\n", " ", $eval))."\n"); //fclose($fp); - eval($eval); + @eval($eval); + if (empty($query)) { + print "eval=".htmlentities($eval)."
";
+		debug_print_backtrace();
+		die("
"); + } if ($run) { // Run SQL query (default) return SQL_QUERY($query, $file, $line); diff --git a/inc/extensions.php b/inc/extensions.php index 711a3d1639..970e0a71ad 100644 --- a/inc/extensions.php +++ b/inc/extensions.php @@ -308,8 +308,10 @@ function EXT_IS_ACTIVE ($ext_name, $ignore_admin = false, $ignore_cache = false) if ((!file_exists($file)) && (!is_readable($file))) return false; //* DEBUG: */ echo "*".$ext_name."(".count($cacheArray).")
"; - // Failed is the default - $ret = false; + // Not active is the default + $active = "N"; + + // Check cache if ((!empty($cacheArray['extensions']['ext_active'][$ext_name])) && (!$ignore_cache)) { // Load from cache //* DEBUG: */ echo "CACHE!
\n"; @@ -317,7 +319,7 @@ function EXT_IS_ACTIVE ($ext_name, $ignore_admin = false, $ignore_cache = false) // Count cache hits if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++; - } else { + } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) { //* DEBUG: */ echo "DB!
\n"; // Load from database $result = SQL_QUERY_ESC("SELECT ext_active FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1", @@ -327,22 +329,27 @@ function EXT_IS_ACTIVE ($ext_name, $ignore_admin = false, $ignore_cache = false) return false; } list($active) = SQL_FETCHROW($result); + //* DEBUG: */ echo $ext_name."[DB]: {$active}
\n"; SQL_FREERESULT($result); // Write cache array $cacheArray['extensions']['ext_active'][$ext_name] = $active; + } else { + // Extension not active! + //* DEBUG: */ echo $ext_name.": Not active!
\n"; + $cacheArray['extensions']['ext_active'][$ext_name] = "N"; } - // Is this extension activated? (For admins we always have active extensions...) + // Create FQFN for extension file $inc = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name); - // Shorter way + + // Debug message + //DEBUG_LOG(__FUNCTION__.": ext_name={$ext_name},active={$active}"); + + // Is this extension activated? (For admins we always have active extensions...) return ( ( - ($active == "Y") || ( - (IS_ADMIN()) && - (!$ignore_admin) && - (!empty($active)) - ) + $active == "Y" ) && ( file_exists($inc) ) && ( @@ -464,16 +471,7 @@ function EXTENSION_UPDATE($file, $ext, $EXT_VER, $dry_run=false) $ext_subj = "[UPDATE-".$ext."-".$EXT_VERSION.":] ".ADMIN_UPDATE_EXT_SUBJ; // Create task - $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1", - array($ext_subj), __FILE__, __LINE__); - if (SQL_NUMROWS($result) == 0) { - // Task not created so it's a brand-new extension which we need to register and create a task for! - $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s', '0', 'NEW', 'EXTENSION_UPDATE', '%s', '%s', UNIX_TIMESTAMP())", - array(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES)), __FILE__, __LINE__); - } - - // Free memory - SQL_FREERESULT($result); + CREATE_EXTENSION_UPDATE_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES)); // Update extension's version $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_version='%s' WHERE ext_name='%s' LIMIT 1", diff --git a/inc/modules/admin/overview-inc.php b/inc/modules/admin/overview-inc.php index aa2f8e7103..c55b3909b4 100644 --- a/inc/modules/admin/overview-inc.php +++ b/inc/modules/admin/overview-inc.php @@ -59,13 +59,12 @@ function OUTPUT_STANDARD_OVERVIEW(&$result_tasks) // Possible newly installed extension found so we extract extension's name $ext = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!! - // Check if extension is installed or not + // Init variables $ext_ver = ""; - if ((!is_array($cacheArray['extensions']['ext_version'])) || (empty($cacheArray['extensions']['ext_version'][$ext]))) { - // Load data from database - $result = SQL_QUERY_ESC("SELECT id, ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1", - array($ext), __FILE__, __LINE__); - } else { + $result = false; + + // Check if extension is installed or not + if ((is_array($cacheArray['extensions']['ext_version'])) && (isset($cacheArray['extensions']['ext_version'][$ext]))) { // Load version from cache if (!empty($cacheArray['extensions']['ext_version'][$ext])) { // Extension is installed so we can get it's version number @@ -77,6 +76,10 @@ function OUTPUT_STANDARD_OVERVIEW(&$result_tasks) // Disable load from database $result = false; + } elseif (!EXT_IS_ACTIVE("cache")) { + // Load data from database + $result = SQL_QUERY_ESC("SELECT id, ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1", + array($ext), __FILE__, __LINE__); } // Is the extension not yet installed? @@ -84,40 +87,8 @@ function OUTPUT_STANDARD_OVERVIEW(&$result_tasks) // Generate subject line $ext_subj = sprintf("[%s:]", $ext); - // Not installed and do we have created a task for the admin? - //* DEBUG: */ echo $ext.":".$ext_ver."="; - $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1", - array($ext_subj), __FILE__, __LINE__); - //* DEBUG: */ echo SQL_NUMROWS($result)."
\n"; - if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) { - // Template file - $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl", - PATH, - GET_LANGUAGE(), - $ext - ); - - // Load text for task - if ((file_exists($tpl)) && (is_readable($tpl))) { - // Load extension's own text template (HTML!) - $MSG = LOAD_TEMPLATE("ext_".$ext, true); - } else { - // Load default message - $MSG = LOAD_EMAIL_TEMPLATE("admin_new_ext","", 0); - } - - // Task not created so it's a brand-new extension which we need to register and create a task for! - $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created) -VALUES ('%s', '0', 'NEW', 'EXTENSION', '%s', '%s', UNIX_TIMESTAMP())", - array( - GET_ADMIN_ID(get_session('admin_login')), - $ext_subj, - addslashes($MSG), - ), __FILE__, __LINE__, true, false); - } - - // Free memory - SQL_FREERESULT($result); + // Create a task for newly installed extension + CREATE_NEW_EXTENSION_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, $ext); // We maybe want to install an extension so let's test-drive it... include(PATH."inc/extensions/".$file); diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index ade9cabcd6..10b170f641 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -693,7 +693,8 @@ function VALIDATE_MENU_ACTION ($MODE, $act, $wht, $UPDATE=false) // Free memory SQL_FREERESULT($result); - //* DEBUG: */ var_dump($ret); + + // Return result return $ret; } // @@ -1321,12 +1322,14 @@ function GET_ADMIN_HASH($login) return $ret; } // -function GET_ADMIN_LOGIN($aid) { +function GET_ADMIN_LOGIN ($aid) { global $cacheArray; $ret = "***"; - if (!empty($cacheArray['admins']['login']['aid'])) { + if (!empty($cacheArray['admins']['login'])) { // Check cache - if (!empty($cacheArray['admins']['login'][$aid])) $ret = $cacheArray['admins']['login'][$aid]; + if (!empty($cacheArray['admins']['login'][$aid])) { + $ret = $cacheArray['admins']['login'][$aid]; + } // END - if if (empty($ret)) $ret = "***"; } else { // Load from database @@ -1335,6 +1338,9 @@ function GET_ADMIN_LOGIN($aid) { if (SQL_NUMROWS($result) == 1) { // Fetch data list($ret) = SQL_FETCHROW($result); + + // Set cache + $cacheArray['admins']['login'][$aid] = $ret; } // Free memory @@ -1585,25 +1591,28 @@ function MODULE_HAS_MENU($mod) if (isset($cacheArray['modules']['has_menu'][$mod])) { // Check module cache and count hit - if ($cacheArray['modules']['has_menu'][$mod] == "Y") $ret = true; + $ret = ($cacheArray['modules']['has_menu'][$mod] == "Y"); $_CONFIG['cache_hits']++; } elseif (isset($cacheArray['extensions']['ext_menu'][$mod])) { // Check cache and count hit - if ($cacheArray['extensions']['ext_menu'][$mod] == "Y") $ret = true; + $ret = ($cacheArray['extensions']['ext_menu'][$mod] == "Y"); $_CONFIG['cache_hits']++; } - } - - if ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ($ret === false)) { + } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && (!EXT_IS_ACTIVE("cache"))) { // Check database for entry $result = SQL_QUERY_ESC("SELECT has_menu FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1", array($mod), __FILE__, __LINE__); if (SQL_NUMROWS($result) == 1) { list($has_menu) = SQL_FETCHROW($result); + + // Fake cache... ;-) + $cacheArray['extensions']['ext_menu'][$mod] = $has_menu; + + // Does it have a menu? $ret = ($has_menu == "Y"); - } + } // END - if // Free memory SQL_FREERESULT($result); @@ -1673,5 +1682,55 @@ function UPDATE_CONFIG ($entries, $values, $updateMode="") { require(PATH."inc/load_cache-config.php"); } // END - if } +// Creates a new task for updated extension +function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $subject, $notes) { + // Check if task is not there + $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1", + array($subject), __FILE__, __LINE__); + if (SQL_NUMROWS($result) == 0) { + // Task not created so it's a brand-new extension which we need to register and create a task for! + $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s', '0', 'NEW', 'EXTENSION_UPDATE', '%s', '%s', UNIX_TIMESTAMP())", + array($admin_id, $subject, $notes), __FILE__, __LINE__); + } // END - if + + // Free memory + SQL_FREERESULT($result); +} +// Creates a new task for newly installed extension +function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) { + // Not installed and do we have created a task for the admin? + $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1", + array($subject), __FILE__, __LINE__); + if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) { + // Template file + $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl", + PATH, + GET_LANGUAGE(), + $ext + ); + + // Load text for task + if ((file_exists($tpl)) && (is_readable($tpl))) { + // Load extension's own text template (HTML!) + $msg = LOAD_TEMPLATE("ext_".$ext, true); + } else { + // Load default message + $msg = LOAD_EMAIL_TEMPLATE("admin_new_ext","", 0); + } + + // Task not created so it's a brand-new extension which we need to register and create a task for! + $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created) +VALUES (%s, 0, 'NEW', 'EXTENSION', '%s', '%s', UNIX_TIMESTAMP())", + array( + $admin_id, + $subject, + addslashes($msg), + ), __FILE__, __LINE__, true, false + ); + } // END - if + + // Free memory + SQL_FREERESULT($result); +} // ?> -- 2.30.2