Compare commits

..

2 commits

Author SHA1 Message Date
rxu
1c399dcab7
[ticket/17491] Consistently apply array_unique to search results
PHPBB-17491
2025-05-06 00:11:45 +07:00
rxu
e91c7d42a9
[ticket/17491] Add test
PHPBB-17491
2025-05-05 23:46:09 +07:00
4 changed files with 22 additions and 21 deletions

View file

@ -609,7 +609,6 @@ class fulltext_mysql extends \phpbb\search\base
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
$id_ary = array_unique($id_ary);
// if the total result count is not cached yet, retrieve it from the db // if the total result count is not cached yet, retrieve it from the db
if (!$result_count && count($id_ary)) if (!$result_count && count($id_ary))
{ {
@ -635,9 +634,9 @@ class fulltext_mysql extends \phpbb\search\base
$id_ary[] = (int) $row[$field]; $id_ary[] = (int) $row[$field];
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
$id_ary = array_unique($id_ary); $id_ary = array_unique($id_ary);
}
// store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page
$this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir);
@ -896,9 +895,9 @@ class fulltext_mysql extends \phpbb\search\base
$id_ary[] = (int) $row[$field]; $id_ary[] = (int) $row[$field];
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
$id_ary = array_unique($id_ary); $id_ary = array_unique($id_ary);
}
if (count($id_ary)) if (count($id_ary))
{ {

View file

@ -1012,6 +1012,8 @@ class fulltext_native extends \phpbb\search\base
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
} }
$id_ary = array_unique($id_ary);
// store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page
$this->save_ids($search_key, $this->search_query, $author_ary, $total_results, $id_ary, $start, $sort_dir); $this->save_ids($search_key, $this->search_query, $author_ary, $total_results, $id_ary, $start, $sort_dir);
$id_ary = array_slice($id_ary, 0, (int) $per_page); $id_ary = array_slice($id_ary, 0, (int) $per_page);
@ -1313,6 +1315,8 @@ class fulltext_native extends \phpbb\search\base
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
} }
$id_ary = array_unique($id_ary);
if (count($id_ary)) if (count($id_ary))
{ {
$this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir); $this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir);

View file

@ -545,8 +545,6 @@ class fulltext_postgres extends \phpbb\search\base
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
$id_ary = array_unique($id_ary);
// if the total result count is not cached yet, retrieve it from the db // if the total result count is not cached yet, retrieve it from the db
if (!$result_count) if (!$result_count)
{ {
@ -576,9 +574,9 @@ class fulltext_postgres extends \phpbb\search\base
$id_ary[] = $row[$field]; $id_ary[] = $row[$field];
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
$id_ary = array_unique($id_ary); $id_ary = array_unique($id_ary);
}
// store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page
$this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir);
@ -858,9 +856,9 @@ class fulltext_postgres extends \phpbb\search\base
$id_ary[] = (int) $row[$field]; $id_ary[] = (int) $row[$field];
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
$id_ary = array_unique($id_ary); $id_ary = array_unique($id_ary);
}
if (count($id_ary)) if (count($id_ary))
{ {

View file

@ -327,30 +327,30 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$cache = $this->get_cache_driver(); $cache = $this->get_cache_driver();
$post_ids_cached = $cache->get($cache_varname); $post_ids_cached = $cache->get($cache_varname);
$cached_results_count = count($post_ids_cached) - 2; // Don't count '-1' and '-2' indexes
$post_ids_cached_backup = $post_ids_cached; $post_ids_cached_backup = $post_ids_cached;
// Cached data still should have initial 'd' sort direction // Cached data still should have initial 'd' sort direction
$this->assertTrue($post_ids_cached[-2] === 'd', $this->search_backend); $this->assertTrue($post_ids_cached[-2] === 'd', $this->search_backend);
// Cached search results count should be more than or equal to displayed one // Cached search results count should be equal to displayed on search results page
$this->assertGreaterThanOrEqual($posts_count, $post_ids_cached[-1], $this->search_backend); $this->assertEquals($posts_count, $post_ids_cached[-1], $this->search_backend);
/* Check post ids cached data. Array shouldn't change after removing duplicates and re-sorting. // Actual cached data array count should be equal to displayed on search results page too
* That means it shouldn't have any duplicates and it should be properly ordered already $this->assertEquals($posts_count, $cached_results_count, $this->search_backend);
*/
// Cached data array shouldn't change after removing duplicates. That is, it shouldn't have any duplicates.
unset($post_ids_cached[-2], $post_ids_cached[-1]); unset($post_ids_cached[-2], $post_ids_cached[-1]);
unset($post_ids_cached_backup[-2], $post_ids_cached_backup[-1]); unset($post_ids_cached_backup[-2], $post_ids_cached_backup[-1]);
$post_ids_cached = array_unique($post_ids_cached); $post_ids_cached = array_unique($post_ids_cached);
rsort($post_ids_cached);
$this->assertEquals($post_ids_cached_backup, $post_ids_cached, $this->search_backend); $this->assertEquals($post_ids_cached_backup, $post_ids_cached, $this->search_backend);
// Restore this value to default // Restore this value to default
$sql = 'UPDATE ' . CONFIG_TABLE . ' $sql = 'UPDATE ' . CONFIG_TABLE . "
SET config_value = ' . floor($posts_count / 3) . " SET config_value = 250
WHERE config_name = '" . $this->db->sql_escape('search_block_size') . "'"; WHERE config_name = '" . $this->db->sql_escape('search_block_size') . "'";
$this->db->sql_query($sql); $this->db->sql_query($sql);
$crawler = self::submit($form);
$this->assertEquals(1, $crawler->filter('.successbox')->count(), $this->search_backend);
// Restore posts_per_page value // Restore posts_per_page value
$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');