From e874ce9898db3f0774f47217611f3cc29f1961f8 Mon Sep 17 00:00:00 2001 From: lavigor Date: Sun, 22 Jul 2018 01:37:00 +0300 Subject: [PATCH] [ticket/13713] Load all data for users in a single SQL query PHPBB3-13713 --- phpBB/phpbb/mention/source/base_user.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/mention/source/base_user.php b/phpBB/phpbb/mention/source/base_user.php index 8ab1d05df1..c47bb313c7 100644 --- a/phpBB/phpbb/mention/source/base_user.php +++ b/phpBB/phpbb/mention/source/base_user.php @@ -81,6 +81,8 @@ abstract class base_user implements source_interface $result = $this->db->sql_query($this->query($keyword, $topic_id), 300); $i = 0; + $users = []; + $user_ids = []; while ($i < self::NAMES_BATCH_SIZE) { $row = $this->db->sql_fetchrow($result); @@ -96,18 +98,26 @@ abstract class base_user implements source_interface } $i++; + $users[] = $row; + $user_ids[] = $row['user_id']; + } - $user_rank = $this->user_loader->get_rank($row['user_id'], true); + // Load all user data with a single SQL query, needed for ranks and avatars + $this->user_loader->load_users($user_ids); + + foreach ($users as $user) + { + $user_rank = $this->user_loader->get_rank($user['user_id'], true); array_push($names, [ - 'name' => $row['username'], + 'name' => $user['username'], 'type' => 'u', - 'id' => $row['user_id'], + 'id' => $user['user_id'], 'avatar' => [ 'type' => 'user', - 'img' => $this->user_loader->get_avatar($row['user_id'], true), + 'img' => $this->user_loader->get_avatar($user['user_id'], true), ], 'rank' => (isset($user_rank['rank_title'])) ? $user_rank['rank_title'] : '', - 'priority' => $this->get_priority($row), + 'priority' => $this->get_priority($user), ]); }