From d6bdd83306f290791151341535b72b0a63847c9d Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 2 Mar 2003 23:16:19 +0000 Subject: [PATCH] - fixed bugs #1395, #1177, fixed floating point assignment bug within older php versions ($fraction), adjusted search a little bit by implementing a workaround for database timeouts (hopefully Paul will not slap me for this. :D) - should be tested within high-traffic boards or those affected by the database timeout. git-svn-id: file:///svn/phpbb/branches/phpBB-2_0_0@3585 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_search.php | 4 +- phpBB/install/update_to_204.php | 2 +- phpBB/install/upgrade.php | 2 +- phpBB/profile.php | 6 +- phpBB/search.php | 213 ++++++++++++------ .../subSilver/privmsgs_read_body.tpl | 2 +- .../templates/subSilver/profile_view_body.tpl | 2 +- 7 files changed, 147 insertions(+), 84 deletions(-) diff --git a/phpBB/includes/functions_search.php b/phpBB/includes/functions_search.php index 0785f9ceba..214f94aee5 100644 --- a/phpBB/includes/functions_search.php +++ b/phpBB/includes/functions_search.php @@ -246,7 +246,7 @@ function add_search_words($mode, $post_id, $post_text, $post_title = '') if ($mode == 'single') { - remove_common('single', 0.4, $word); + remove_common('single', 4/10, $word); } return; @@ -486,4 +486,4 @@ function username_search($search_match) return; } -?> +?> \ No newline at end of file diff --git a/phpBB/install/update_to_204.php b/phpBB/install/update_to_204.php index af24fe29e6..7cbd4a3843 100644 --- a/phpBB/install/update_to_204.php +++ b/phpBB/install/update_to_204.php @@ -712,7 +712,7 @@ switch ($row['config_value']) closedir($dir); // Mark common words ... - remove_common('global', 0.4); + remove_common('global', 4/10); // remove superfluous polls ... grab polls with topics then delete polls // not in that list diff --git a/phpBB/install/upgrade.php b/phpBB/install/upgrade.php index 9fdcc9e393..6391310f05 100644 --- a/phpBB/install/upgrade.php +++ b/phpBB/install/upgrade.php @@ -1926,7 +1926,7 @@ if ( !empty($next) ) // Remove common words after the first 2 batches and after every 4th batch after that. if ( $batchcount % 4 == 3 ) { - remove_common('global', 0.4); + remove_common('global', 4/10); } print " OK
\n"; diff --git a/phpBB/profile.php b/phpBB/profile.php index 3d96605640..54cd4c9670 100644 --- a/phpBB/profile.php +++ b/phpBB/profile.php @@ -115,9 +115,7 @@ if ( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) ) exit; } } -else -{ - redirect(append_sid("index.$phpEx", true)); -} + +redirect(append_sid("index.$phpEx", true)); ?> \ No newline at end of file diff --git a/phpBB/search.php b/phpBB/search.php index 0da49d490a..c84dc0c183 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -145,6 +145,10 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id ) { $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars'); + // + // Search ID Limiter, decrease this value if you experience further timeout problems with searching forums + $limiter = 5000; + // // Cycle through options ... // @@ -175,7 +179,7 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id ) { $sql = "SELECT post_id FROM " . POSTS_TABLE . " - WHERE poster_id = " . $userdata['user_id'];; + WHERE poster_id = " . $userdata['user_id']; } else { @@ -215,6 +219,11 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id ) $sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE poster_id IN ($matching_userids)"; + + if ($search_time) + { + $sql .= " AND post_time >= " . $search_time; + } } if ( !($result = $db->sql_query($sql)) ) @@ -400,29 +409,124 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id ) { if ( $show_results == 'topics' ) { - $where_sql = ''; + // + // This one is a beast, try to seperate it a bit (workaround for connection timeouts) + // + $search_id_chunks = array(); + $count = 0; + $chunk = 0; - if ( $search_time ) + if (count($search_ids) > $limiter) { - $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time "; - } - - if ( $search_author == '' && $auth_sql == '' ) - { - $sql = "SELECT topic_id - FROM " . POSTS_TABLE . " - WHERE post_id IN (" . implode(", ", $search_ids) . ") - $where_sql - GROUP BY topic_id"; + for ($i = 0; $i < count($search_ids); $i++) + { + if ($count == $limiter) + { + $chunk++; + $count = 0; + } + + $search_id_chunks[$chunk][$count] = $search_ids[$i]; + $count++; + } } else { - $from_sql = POSTS_TABLE . " p"; + $search_id_chunks[0] = $search_ids; + } - if ( $search_author != '' ) + $search_ids = array(); + + for ($i = 0; $i < count($search_id_chunks); $i++) + { + $where_sql = ''; + + if ( $search_time ) { - $from_sql .= ", " . USERS_TABLE . " u"; - $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' "; + $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time "; + } + + if ( $search_author == '' && $auth_sql == '' ) + { + $sql = "SELECT topic_id + FROM " . POSTS_TABLE . " + WHERE post_id IN (" . implode(", ", $search_id_chunks[$i]) . ") + $where_sql + GROUP BY topic_id"; + } + else + { + $from_sql = POSTS_TABLE . " p"; + + if ( $search_author != '' ) + { + $from_sql .= ", " . USERS_TABLE . " u"; + $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' "; + } + + if ( $auth_sql != '' ) + { + $from_sql .= ", " . FORUMS_TABLE . " f"; + $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; + } + + $sql = "SELECT p.topic_id + FROM $from_sql + WHERE p.post_id IN (" . implode(", ", $search_id_chunks[$i]) . ") + $where_sql + GROUP BY p.topic_id"; + } + + if ( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql); + } + + while ($row = $db->sql_fetchrow($result)) + { + $search_ids[] = $row['topic_id']; + } + $db->sql_freeresult($result); + } + + $total_match_count = sizeof($search_ids); + + } + else if ( $search_author != '' || $search_time || $auth_sql != '' ) + { + $search_id_chunks = array(); + $count = 0; + $chunk = 0; + + if (count($search_ids) > $limiter) + { + for ($i = 0; $i < count($search_ids); $i++) + { + if ($count == $limiter) + { + $chunk++; + $count = 0; + } + + $search_id_chunks[$chunk][$count] = $search_ids[$i]; + $count++; + } + } + else + { + $search_id_chunks[0] = $search_ids; + } + + $search_ids = array(); + + for ($i = 0; $i < count($search_id_chunks); $i++) + { + $where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')' : 'p.post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')'; + $from_sql = ( $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p'; + + if ( $search_time ) + { + $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time"; } if ( $auth_sql != '' ) @@ -431,66 +535,27 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id ) $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; } - $sql = "SELECT p.topic_id + if ( $search_author != '' ) + { + $from_sql .= ", " . USERS_TABLE . " u"; + $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'"; + } + + $sql = "SELECT p.post_id FROM $from_sql - WHERE p.post_id IN (" . implode(", ", $search_ids) . ") - $where_sql - GROUP BY p.topic_id"; + WHERE $where_sql"; + if ( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql); + } + + while( $row = $db->sql_fetchrow($result) ) + { + $search_ids[] = $row['post_id']; + } + $db->sql_freeresult($result); } - if ( !($result = $db->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql); - } - - $search_ids = array(); - while( $row = $db->sql_fetchrow($result) ) - { - $search_ids[] = $row['topic_id']; - } - $db->sql_freeresult($result); - - $total_match_count = sizeof($search_ids); - - } - else if ( $search_author != '' || $search_time || $auth_sql != '' ) - { - $where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_ids) . ')' : 'p.post_id IN (' . implode(', ', $search_ids) . ')'; - $from_sql = ( $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p'; - - if ( $search_time ) - { - $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time"; - } - - if ( $auth_sql != '' ) - { - $from_sql .= ", " . FORUMS_TABLE . " f"; - $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; - } - - if ( $search_author != '' ) - { - $from_sql .= ", " . USERS_TABLE . " u"; - $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'"; - } - - $sql = "SELECT p.post_id - FROM $from_sql - WHERE $where_sql"; - if ( !($result = $db->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql); - } - - $search_ids = array(); - while( $row = $db->sql_fetchrow($result) ) - { - $search_ids[] = $row['post_id']; - } - - $db->sql_freeresult($result); - $total_match_count = count($search_ids); } } diff --git a/phpBB/templates/subSilver/privmsgs_read_body.tpl b/phpBB/templates/subSilver/privmsgs_read_body.tpl index f9ebf0c225..3c85e6a125 100644 --- a/phpBB/templates/subSilver/privmsgs_read_body.tpl +++ b/phpBB/templates/subSilver/privmsgs_read_body.tpl @@ -53,7 +53,7 @@ {PROFILE_IMG} {PM_IMG} {EMAIL_IMG} {WWW_IMG} {AIM_IMG} {YIM_IMG} {MSN_IMG}