diff options
author | Andreas Fischer <bantu@phpbb.com> | 2012-02-26 15:47:16 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2012-02-26 15:47:16 +0100 |
commit | af23811c6d66d5d824563ed8c09f3bcfbba8aa71 (patch) | |
tree | 93a6448fa9c6db63dea374b50374962ba46d0c88 /phpBB/search.php | |
parent | 2f916233924eb378cc9d03958dfc7da30d45814d (diff) | |
parent | 8910ec98d7aa685d497841e4c60473ca205ec355 (diff) | |
download | forums-af23811c6d66d5d824563ed8c09f3bcfbba8aa71.tar forums-af23811c6d66d5d824563ed8c09f3bcfbba8aa71.tar.gz forums-af23811c6d66d5d824563ed8c09f3bcfbba8aa71.tar.bz2 forums-af23811c6d66d5d824563ed8c09f3bcfbba8aa71.tar.xz forums-af23811c6d66d5d824563ed8c09f3bcfbba8aa71.zip |
Merge branch 'develop-olympus' into develop
* develop-olympus:
[ticket/10532] Remove unnecessary parentheses around calculations of addition.
[ticket/10532] Remove one unnecessary level of if block nesting.
[ticket/10532] Get rid of inline calculation of $start, remove duplicated check
[ticket/10532] Put $total_match_count assignment onto its own line.
[ticket/10532] Adjust total match count and limit
[ticket/10532] Fix $start out of range for pre-made searches
Conflicts:
phpBB/search.php
Diffstat (limited to 'phpBB/search.php')
-rw-r--r-- | phpBB/search.php | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/phpBB/search.php b/phpBB/search.php index 4f30cdc1dd..2b463aec9c 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -465,33 +465,60 @@ if ($keywords || $author || $author_id || $search_id || $submit) $per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page']; $total_match_count = 0; + // Set limit for the $total_match_count to reduce server load + $total_matches_limit = 1000; + $found_more_search_matches = false; + if ($search_id) { if ($sql) { - // only return up to 1000 ids (the last one will be removed later) - $result = $db->sql_query_limit($sql, 1001 - $start, $start); + // Only return up to $total_matches_limit+1 ids (the last one will be removed later) + $result = $db->sql_query_limit($sql, $total_matches_limit + 1); while ($row = $db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } $db->sql_freeresult($result); - - $total_match_count = sizeof($id_ary) + $start; - $id_ary = array_slice($id_ary, 0, $per_page); } else if ($search_id == 'unreadposts') { - $id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $start, $start)); - - $total_match_count = sizeof($id_ary) + $start; - $id_ary = array_slice($id_ary, 0, $per_page); + // Only return up to $total_matches_limit+1 ids (the last one will be removed later) + $id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, $total_matches_limit + 1)); } else { $search_id = ''; } + + $total_match_count = sizeof($id_ary); + if ($total_match_count) + { + // Limit the number to $total_matches_limit for pre-made searches + if ($total_match_count > $total_matches_limit) + { + $found_more_search_matches = true; + $total_match_count = $total_matches_limit; + } + + // Make sure $start is set to the last page if it exceeds the amount + if ($start < 0) + { + $start = 0; + } + else if ($start >= $total_match_count) + { + $start = floor(($total_match_count - 1) / $per_page) * $per_page; + } + + $id_ary = array_slice($id_ary, $start, $per_page); + } + else + { + // Set $start to 0 if no matches were found + $start = 0; + } } // make sure that some arrays are always in the same order @@ -539,10 +566,8 @@ if ($keywords || $author || $author_id || $search_id || $submit) $icons = $cache->obtain_icons(); // Output header - if ($search_id && ($total_match_count > 1000)) + if ($found_more_search_matches) { - // limit the number to 1000 for pre-made searches - $total_match_count--; $l_search_matches = $user->lang('FOUND_MORE_SEARCH_MATCHES', (int) $total_match_count); } else |