mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-13 20:28:44 +01:00
[ticket/9606] Optimize unread search option.
Get rid of redundant SQL query in search.php that should increase performance slightly. PHPBB3-9606
This commit is contained in:
parent
6d7e30ae99
commit
d819ee343a
@ -1660,10 +1660,11 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis
|
||||
* @param string $sql_extra Extra WHERE SQL statement
|
||||
* @param string $sql_sort ORDER BY SQL sorting statement
|
||||
* @param string $sql_limit Limits the size of unread topics list, 0 for unlimited query
|
||||
* @param string $sql_limit_offset Sets the offset of the first row to search, 0 to search from the start
|
||||
*
|
||||
* @return array[int][int] Topic ids as keys, mark_time of topic as value
|
||||
*/
|
||||
function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001)
|
||||
function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)
|
||||
{
|
||||
global $config, $db, $user;
|
||||
|
||||
@ -1709,7 +1710,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s
|
||||
);
|
||||
|
||||
$sql = $db->sql_build_query('SELECT', $sql_array);
|
||||
$result = $db->sql_query_limit($sql, $sql_limit);
|
||||
$result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
@ -1742,7 +1743,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s
|
||||
WHERE t.topic_last_post_time > ' . $user_lastmark . "
|
||||
$sql_extra
|
||||
$sql_sort";
|
||||
$result = $db->sql_query_limit($sql, $sql_limit);
|
||||
$result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
|
@ -387,18 +387,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||
|
||||
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
||||
$s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
|
||||
|
||||
$unread_list = array();
|
||||
$unread_list = get_unread_topics($user->data['user_id'], $sql_where, $sql_sort);
|
||||
|
||||
if (!empty($unread_list))
|
||||
{
|
||||
$sql = 'SELECT t.topic_id
|
||||
FROM ' . TOPICS_TABLE . ' t
|
||||
WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . "
|
||||
$sql_sort";
|
||||
$field = 'topic_id';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'newposts':
|
||||
@ -476,6 +464,13 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||
$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);
|
||||
}
|
||||
else
|
||||
{
|
||||
$search_id = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user