[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
This commit is contained in:
Dark❶ 2021-12-12 19:51:50 +05:30
parent 391e4943d9
commit 65fa73855c
No known key found for this signature in database
GPG key ID: B5C35684F456E634

View file

@ -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();