diff --git a/phpBB/phpbb/mention/source/base_group.php b/phpBB/phpbb/mention/source/base_group.php index c8d498ce81..1f3f063e33 100644 --- a/phpBB/phpbb/mention/source/base_group.php +++ b/phpBB/phpbb/mention/source/base_group.php @@ -36,6 +36,9 @@ abstract class base_group implements source_interface /** @var string */ protected $php_ext; + /** @var string|false */ + protected $cache_ttl = false; + /** @var array Fetched groups' data */ protected $groups = null; @@ -125,8 +128,8 @@ abstract class base_group implements source_interface */ public function get(array &$names, $keyword, $topic_id) { - // Grab all group IDs, cache for 5 minutes - $result = $this->db->sql_query($this->query($keyword, $topic_id), 300); + // Grab all group IDs and cache them if needed + $result = $this->db->sql_query($this->query($keyword, $topic_id), $this->cache_ttl); $group_ids = []; while ($row = $this->db->sql_fetchrow($result)) diff --git a/phpBB/phpbb/mention/source/base_user.php b/phpBB/phpbb/mention/source/base_user.php index e002840614..8b6c7a8540 100644 --- a/phpBB/phpbb/mention/source/base_user.php +++ b/phpBB/phpbb/mention/source/base_user.php @@ -30,6 +30,9 @@ abstract class base_user implements source_interface /** @var string */ protected $php_ext; + /** @var string|false */ + protected $cache_ttl = false; + /** * Constructor */ @@ -73,47 +76,67 @@ abstract class base_user implements source_interface $fetched_all = false; $keyword = utf8_clean_string($keyword); - // Grab all necessary user IDs, cache results for 5 minutes - $result = $this->db->sql_query($this->query($keyword, $topic_id), 300); - $i = 0; $users = []; $user_ids = []; - while ($i < $this->config['mention_batch_size']) + + // Grab all necessary user IDs and cache them if needed + if ($this->cache_ttl) { - $row = $this->db->sql_fetchrow($result); + $result = $this->db->sql_query($this->query($keyword, $topic_id), $this->cache_ttl); - if (!$row) + while ($i < $this->config['mention_batch_size']) { - $fetched_all = true; - break; - } + $row = $this->db->sql_fetchrow($result); - if (!empty($keyword) && strpos($row['username_clean'], $keyword) !== 0) - { - continue; - } + if (!$row) + { + $fetched_all = true; + break; + } - $i++; - $users[] = $row; - $user_ids[] = $row['user_id']; - } - - // Determine whether all usernames were fetched in current batch - if (!$fetched_all) - { - $fetched_all = true; - - while ($row = $this->db->sql_fetchrow($result)) - { if (!empty($keyword) && strpos($row['username_clean'], $keyword) !== 0) { continue; } - // At least one username hasn't been fetched - exit loop - $fetched_all = false; - break; + $i++; + $users[] = $row; + $user_ids[] = $row['user_id']; + } + + // Determine whether all usernames were fetched in current batch + if (!$fetched_all) + { + $fetched_all = true; + + while ($row = $this->db->sql_fetchrow($result)) + { + if (!empty($keyword) && strpos($row['username_clean'], $keyword) !== 0) + { + continue; + } + + // At least one username hasn't been fetched - exit loop + $fetched_all = false; + break; + } + } + } + else + { + $result = $this->db->sql_query_limit($this->query($keyword, $topic_id), $this->config['mention_batch_size'], 0); + + while ($row = $this->db->sql_fetchrow($result)) + { + $users[] = $row; + $user_ids[] = $row['user_id']; + } + + // Determine whether all usernames were fetched in current batch + if (count($user_ids) < $this->config['mention_batch_size']) + { + $fetched_all = true; } } diff --git a/phpBB/phpbb/mention/source/friend.php b/phpBB/phpbb/mention/source/friend.php index f68bea175a..ca16a374b5 100644 --- a/phpBB/phpbb/mention/source/friend.php +++ b/phpBB/phpbb/mention/source/friend.php @@ -50,7 +50,8 @@ class friend extends base_user ] ], 'WHERE' => 'z.friend = 1 AND z.user_id = ' . (int) $this->user->data['user_id'] . ' - AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]), + AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . ' + AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()), 'ORDER_BY' => 'u.user_lastvisit DESC' ]); return $query; diff --git a/phpBB/phpbb/mention/source/group.php b/phpBB/phpbb/mention/source/group.php index e74948d402..2b13ca7be0 100644 --- a/phpBB/phpbb/mention/source/group.php +++ b/phpBB/phpbb/mention/source/group.php @@ -15,6 +15,9 @@ namespace phpbb\mention\source; class group extends base_group { + /** @var string|false */ + protected $cache_ttl = 300; + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/mention/source/team.php b/phpBB/phpbb/mention/source/team.php index 4b40d7f224..14281a85bf 100644 --- a/phpBB/phpbb/mention/source/team.php +++ b/phpBB/phpbb/mention/source/team.php @@ -15,6 +15,9 @@ namespace phpbb\mention\source; class team extends base_user { + /** @var string|false */ + protected $cache_ttl = 300; + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/mention/source/topic.php b/phpBB/phpbb/mention/source/topic.php index 51b855e97b..0c630aa22e 100644 --- a/phpBB/phpbb/mention/source/topic.php +++ b/phpBB/phpbb/mention/source/topic.php @@ -61,7 +61,8 @@ class topic extends base_user ], ], 'WHERE' => 'p.topic_id = ' . (int) $topic_id . ' - AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]), + AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . ' + AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()), 'ORDER_BY' => 'p.post_time DESC' ]); return $query; diff --git a/phpBB/phpbb/mention/source/user.php b/phpBB/phpbb/mention/source/user.php index 57f1a23eab..a85d3d3be4 100644 --- a/phpBB/phpbb/mention/source/user.php +++ b/phpBB/phpbb/mention/source/user.php @@ -39,7 +39,8 @@ class user extends base_user 'FROM' => [ USERS_TABLE => 'u', ], - 'WHERE' => $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]), + 'WHERE' => $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . ' + AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()), 'ORDER_BY' => 'u.user_lastvisit DESC' ]); return $query;