mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/10532] Adjust total match count and limit
Set a variable for the limit of total matches count. Adjust total match count to limit to provide proper $start value calculation. Adjust $start value if no matches were found. PHPBB3-10532
This commit is contained in:
parent
c9733ad719
commit
cb7bb31129
1 changed files with 21 additions and 6 deletions
|
@ -469,14 +469,18 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
|
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
|
||||||
$total_match_count = 0;
|
$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 ($search_id)
|
||||||
{
|
{
|
||||||
if ($sql || $search_id == 'unreadposts')
|
if ($sql || $search_id == 'unreadposts')
|
||||||
{
|
{
|
||||||
if ($sql)
|
if ($sql)
|
||||||
{
|
{
|
||||||
// only return up to 1000 ids (the last one will be removed later)
|
// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
|
||||||
$result = $db->sql_query_limit($sql, 1001);
|
$result = $db->sql_query_limit($sql, ($total_matches_limit + 1));
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
|
@ -486,11 +490,19 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
}
|
}
|
||||||
else if ($search_id == 'unreadposts')
|
else if ($search_id == 'unreadposts')
|
||||||
{
|
{
|
||||||
$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001));
|
// 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($total_match_count = sizeof($id_ary))
|
if ($total_match_count = sizeof($id_ary))
|
||||||
{
|
{
|
||||||
|
// 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
|
// Make sure $start is set to the last page if it exceeds the amount
|
||||||
if ($start < 0 || $start >= $total_match_count)
|
if ($start < 0 || $start >= $total_match_count)
|
||||||
{
|
{
|
||||||
|
@ -498,6 +510,11 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
}
|
}
|
||||||
$id_ary = array_slice($id_ary, $start, $per_page);
|
$id_ary = array_slice($id_ary, $start, $per_page);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Set $start to 0 if no matches were found
|
||||||
|
$start = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -550,10 +567,8 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
$icons = $cache->obtain_icons();
|
$icons = $cache->obtain_icons();
|
||||||
|
|
||||||
// Output header
|
// 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 = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
|
$l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue