From 65fa73855cc11ecf8010b9614979a41d235fbf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= <25451052+Dark1z@users.noreply.github.com> Date: Sun, 12 Dec 2021 19:51:50 +0530 Subject: [PATCH 1/5] [ticket/16940] Optimize phpBB Native Search - Use `sql_query_limit` instead of `sql_query` - Update SQL query to reflect the above change - Assign proper last `post_id` to `$post_counter` PHPBB3-16940 --- phpBB/includes/acp/acp_search.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 3b6febd566..e3a50b718b 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -322,9 +322,8 @@ class acp_search { $sql = 'SELECT post_id, poster_id, forum_id FROM ' . POSTS_TABLE . ' - WHERE post_id >= ' . (int) ($post_counter + 1) . ' - AND post_id <= ' . (int) ($post_counter + $this->batch_size); - $result = $db->sql_query($sql); + WHERE post_id > ' . (int) $post_counter; + $result = $db->sql_query_limit($sql, $this->batch_size); $ids = $posters = $forum_ids = array(); while ($row = $db->sql_fetchrow($result)) @@ -341,7 +340,7 @@ class acp_search $this->search->index_remove($ids, $posters, $forum_ids); } - $post_counter += $this->batch_size; + $post_counter = end($ids); } // save the current state $this->save_state(); @@ -393,9 +392,8 @@ class acp_search { $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . POSTS_TABLE . ' - WHERE post_id >= ' . (int) ($post_counter + 1) . ' - AND post_id <= ' . (int) ($post_counter + $this->batch_size); - $result = $db->sql_query($sql); + WHERE post_id > ' . (int) $post_counter; + $result = $db->sql_query_limit($sql, $this->batch_size); $buffer = $db->sql_buffer_nested_transactions(); @@ -416,13 +414,12 @@ class acp_search $this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']); } $row_count++; + $post_counter = $row['post_id']; } if (!$buffer) { $db->sql_freeresult($result); } - - $post_counter += $this->batch_size; } // save the current state $this->save_state(); From ddc3eaa5bfcf9ed82d6de446fcd6678a335e42c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= <25451052+Dark1z@users.noreply.github.com> Date: Sun, 12 Dec 2021 20:44:37 +0530 Subject: [PATCH 2/5] [ticket/16940] Optimize phpBB Native Search - Removed `end()` replaced with `$ids[count($ids) - 1]` PHPBB3-16940 --- phpBB/includes/acp/acp_search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index e3a50b718b..5bc3c42a77 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -340,7 +340,7 @@ class acp_search $this->search->index_remove($ids, $posters, $forum_ids); } - $post_counter = end($ids); + $post_counter = $ids[count($ids) - 1]; } // save the current state $this->save_state(); From cccf01447f22e38d60ac71b0f85af324b462ddd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= <25451052+Dark1z@users.noreply.github.com> Date: Mon, 13 Dec 2021 00:37:04 +0530 Subject: [PATCH 3/5] [ticket/16940] Optimize phpBB Native Search - Fixed infinite loop PHPBB3-16940 --- phpBB/includes/acp/acp_search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 5bc3c42a77..130a46e918 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -345,7 +345,7 @@ class acp_search // save the current state $this->save_state(); - if ($post_counter <= $this->max_post_id) + if ($post_counter < $this->max_post_id) { $totaltime = microtime(true) - $starttime; $rows_per_second = $row_count / $totaltime; @@ -431,7 +431,7 @@ class acp_search $this->search->tidy(); $config['num_posts'] = $num_posts; - if ($post_counter <= $this->max_post_id) + if ($post_counter < $this->max_post_id) { $totaltime = microtime(true) - $starttime; $rows_per_second = $row_count / $totaltime; From c7856ce162bbb0f90873af1f4099468a51f26ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= <25451052+Dark1z@users.noreply.github.com> Date: Mon, 13 Dec 2021 19:36:36 +0530 Subject: [PATCH 4/5] [ticket/16940] Optimize phpBB Native Search - Use `ORDER BY post_id ASC` for batch posts. PHPBB3-16940 --- phpBB/includes/acp/acp_search.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 130a46e918..33471c1842 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -322,7 +322,8 @@ class acp_search { $sql = 'SELECT post_id, poster_id, forum_id FROM ' . POSTS_TABLE . ' - WHERE post_id > ' . (int) $post_counter; + WHERE post_id > ' . (int) $post_counter . ' + ORDER BY post_id ASC'; $result = $db->sql_query_limit($sql, $this->batch_size); $ids = $posters = $forum_ids = array(); @@ -392,7 +393,8 @@ class acp_search { $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . POSTS_TABLE . ' - WHERE post_id > ' . (int) $post_counter; + WHERE post_id > ' . (int) $post_counter . ' + ORDER BY post_id ASC'; $result = $db->sql_query_limit($sql, $this->batch_size); $buffer = $db->sql_buffer_nested_transactions(); From fad1c652c0fde2a27e861db35069e8a23105c10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= <25451052+Dark1z@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:26:39 +0530 Subject: [PATCH 5/5] [ticket/16940] Optimize phpBB Native Search PHPBB3-16940 --- phpBB/includes/acp/acp_search.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 33471c1842..c4bf11e4cf 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -339,9 +339,8 @@ class acp_search if (count($ids)) { $this->search->index_remove($ids, $posters, $forum_ids); + $post_counter = $ids[count($ids) - 1]; } - - $post_counter = $ids[count($ids) - 1]; } // save the current state $this->save_state();