From cf54570f6c3ad03065df9ff18a57cac145305443 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 31 Dec 2004 13:58:41 +0000 Subject: [PATCH] - fixed [code=php] - optimized db/mysql.php a little bit git-svn-id: file:///svn/phpbb/trunk@5037 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 48 +++++++++++++++------------- phpBB/includes/functions.php | 5 +-- phpBB/includes/functions_display.php | 2 +- phpBB/includes/message_parser.php | 3 ++ 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 8b08b33458..6cf0b07126 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -57,9 +57,9 @@ class sql_db return false; } - if (count($this->open_queries)) + if (sizeof($this->open_queries)) { - foreach ($this->open_queries as $query_id) + foreach ($this->open_queries as $i_query_id => $query_id) { @mysql_free_result($query_id); } @@ -111,8 +111,11 @@ class sql_db { global $cache; - // DEBUG - $this->sql_report('start', $query); + // EXPLAIN only in extra debug mode + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('start', $query); + } $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; @@ -125,22 +128,24 @@ class sql_db $this->sql_error($query); } - // DEBUG - $this->sql_report('stop', $query); + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('stop', $query); + } if ($cache_ttl && method_exists($cache, 'sql_save')) { + $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); - // mysql_free_result happened within sql_save() + // mysql_free_result called within sql_save() } - elseif (preg_match('/^SELECT/', $query)) + else if (strpos($query, 'SELECT') !== false && $this->query_result) { - $this->open_queries[] = $this->query_result; + $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else + else if (defined('DEBUG_EXTRA')) { - // DEBUG $this->sql_report('fromcache', $query); } } @@ -258,7 +263,9 @@ class sql_db $query_id = $this->query_result; } - if (method_exists($cache, 'sql_fetchrow') && $cache->sql_exists($query_id)) + // This method is called too often... do not waste memory by calling/checking unneeded things +// if (method_exists($cache, 'sql_fetchrow') && $cache->sql_exists($query_id)) + if (isset($cache->sql_rowset[$query_id])) { return $cache->sql_fetchrow($query_id); } @@ -345,17 +352,13 @@ class sql_db $query_id = $this->query_result; } - if ($query_id) + if (isset($this->open_queries[(int) $query_id])) { - // If it is not found within the open queries, we try to free a cached result. ;) - if (!(array_search($query_id, $this->open_queries) > 0)) - { - return false; - } - unset($this->open_queries[array_search($query_id, $this->open_queries)]); + unset($this->open_queries[(int) $query_id]); + return @mysql_free_result($query_id); } - return ($query_id) ? @mysql_free_result($query_id) : false; + return false; } function sql_escape($msg) @@ -367,8 +370,8 @@ class sql_db { if (!$this->return_on_error) { - $this_page = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; - $this_page .= '&' . ((!empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']); + $this_page = (isset($_SERVER['PHP_SELF']) && !empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; + $this_page .= '&' . ((isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : (isset($_ENV['QUERY_STRING']) ? $_ENV['QUERY_STRING'] : '')); $message = 'SQL ERROR [ ' . SQL_LAYER . ' ]

' . @mysql_error() . '

CALLING PAGE

' . htmlspecialchars($this_page) . (($sql != '') ? '

SQL

' . $sql : '') . '
'; @@ -388,7 +391,6 @@ class sql_db return $result; } - // DEBUG function sql_report($mode, $query = '') { if (empty($_GET['explain'])) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 891c169dc5..8d3965d8d5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1389,7 +1389,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) if (defined('DEBUG_EXTRA')) { // Remove me - if (!strstr($errfile, '/cache/') && !strstr($errfile, 'mysql.php') && !strstr($errfile, 'template.php')) + if (!strstr($errfile, '/cache/') && !strstr($errfile, 'template.php')) { echo "PHP Notice: in file $errfile on line $errline: $msg_text
"; } @@ -1533,7 +1533,7 @@ function page_header($page_title = '') $reading_sql AND u.user_id = s.session_user_id ORDER BY u.username ASC, s.session_ip ASC"; - $result = $db->sql_query($sql, false); + $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { @@ -1579,6 +1579,7 @@ function page_header($page_title = '') $prev_session_ip = $row['session_ip']; } + $db->sql_freeresult($result); if (!$online_userlist) { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index a01f58d9b6..4bceade633 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -162,7 +162,7 @@ function display_forums($root_data = '', $display_moderators = TRUE) $forum_unread[$parent_id] = true; } } - $db->sql_freeresult(); + $db->sql_freeresult($result); // Handle marking posts if ($mark_read == 'forums') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 00c57c81e6..7caadd123e 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -234,6 +234,9 @@ class bbcode_firstpass extends bbcode ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var)); } + // Because highlight_string is specialcharing the text (but we already did this before), we have to reverse this in order to get correct results + $code = strtr($code, array_flip(get_html_translation_table(HTML_ENTITIES))); + ob_start(); highlight_string($code); $code = ob_get_contents();