1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-28 10:09:15 +02:00

[ticket/13713] Fix priorities

PHPBB3-13713
This commit is contained in:
lavigor 2018-07-22 03:58:00 +03:00 committed by Marc Alexander
parent 6f8467a2fa
commit e616ec025c
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
6 changed files with 62 additions and 7 deletions

View File

@ -46,7 +46,7 @@ class mention
{
if (!$this->request->is_ajax())
{
new RedirectResponse(append_sid($this->phpbb_root_path . 'index.' . $this->php_ext));
return new RedirectResponse(append_sid($this->phpbb_root_path . 'index.' . $this->php_ext));
}
$keyword = $this->request->variable('keyword', '', true);

View File

@ -15,6 +15,20 @@ namespace phpbb\mention\source;
class group extends base_group
{
/**
* {@inheritdoc}
*/
public function get_priority($row)
{
/*
* Presence in array with all names for this type should not increase the priority
* Otherwise names will not be properly sorted because we fetch them in batches
* and the name from 'special' source can be absent from the array with all names
* and therefore it will appear lower than needed
*/
return 0;
}
/**
* {@inheritdoc}
*/

View File

@ -27,6 +27,8 @@ interface source_interface
/**
* Returns the priority of the currently selected name
* Please note that simple inner priorities for a certain source
* can be set with ORDER BY SQL clause
*
* @param array $row Array of fetched data for the name type (e.g. user row)
* @return int Priority (defaults to 1)

View File

@ -21,11 +21,14 @@ class team extends base_user
protected function query($keyword, $topic_id)
{
/*
* Select unique names of team members: each name should be selected only once
* regardless of the number of groups the certain user is a member of
*
* For optimization purposes all team members are returned regardless of the keyword
* Names filtering is done on the frontend
* Results will be cached in a single file
*/
$query = $this->db->sql_build_query('SELECT', [
$query = $this->db->sql_build_query('SELECT_DISTINCT', [
'SELECT' => 'u.username_clean, u.username, u.user_id',
'FROM' => [
USERS_TABLE => 'u',

View File

@ -15,18 +15,38 @@ namespace phpbb\mention\source;
class topic extends base_user
{
/**
* {@inheritdoc}
*/
public function get_priority($row)
{
/*
* Topic's open poster is probably the most mentionable user in the topic
* so we give him a significant priority
*/
if ($row['user_id'] === $row['topic_poster'])
{
return 5;
}
return 1;
}
/**
* {@inheritdoc}
*/
protected function query($keyword, $topic_id)
{
/*
* Select poster's username together with topic author's ID
* that will be later used for priotirisation
*
* For optimization purposes all users are returned regardless of the keyword
* Names filtering is done on the frontend
* Results will be cached on a per-topic basis
*/
$query = $this->db->sql_build_query('SELECT', [
'SELECT' => 'u.username, u.user_id',
'SELECT' => 'u.username, u.user_id, t.topic_poster',
'FROM' => [
USERS_TABLE => 'u',
],
@ -34,7 +54,11 @@ class topic extends base_user
[
'FROM' => [POSTS_TABLE => 'p'],
'ON' => 'u.user_id = p.poster_id'
]
],
[
'FROM' => [TOPICS_TABLE => 't'],
'ON' => 't.topic_id = p.topic_id'
],
],
'WHERE' => 'p.topic_id = ' . $topic_id . '
AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]),

View File

@ -15,19 +15,31 @@ namespace phpbb\mention\source;
class user extends base_user
{
/**
* {@inheritdoc}
*/
public function get_priority($row)
{
/*
* Presence in array with all names for this type should not increase the priority
* Otherwise names will not be properly sorted because we fetch them in batches
* and the name from 'special' source can be absent from the array with all names
* and therefore it will appear lower than needed
*/
return 0;
}
/**
* {@inheritdoc}
*/
protected function query($keyword, $topic_id)
{
// TODO: think about caching ALL users: 1m users results to ~40MB file
$query = $this->db->sql_build_query('SELECT', [
'SELECT' => 'u.username_clean, u.username, u.user_id',
'FROM' => [
USERS_TABLE => 'u',
],
'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())*/,
'WHERE' => $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]),
'ORDER_BY' => 'u.user_lastvisit DESC'
]);
return $query;