mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 12:28:52 +00:00
[ticket/13713] Fix priorities
PHPBB3-13713
This commit is contained in:
parent
6f8467a2fa
commit
e616ec025c
6 changed files with 62 additions and 7 deletions
|
@ -46,7 +46,7 @@ class mention
|
||||||
{
|
{
|
||||||
if (!$this->request->is_ajax())
|
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);
|
$keyword = $this->request->variable('keyword', '', true);
|
||||||
|
|
|
@ -15,6 +15,20 @@ namespace phpbb\mention\source;
|
||||||
|
|
||||||
class group extends base_group
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,8 @@ interface source_interface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the priority of the currently selected name
|
* 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)
|
* @param array $row Array of fetched data for the name type (e.g. user row)
|
||||||
* @return int Priority (defaults to 1)
|
* @return int Priority (defaults to 1)
|
||||||
|
|
|
@ -21,11 +21,14 @@ class team extends base_user
|
||||||
protected function query($keyword, $topic_id)
|
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
|
* For optimization purposes all team members are returned regardless of the keyword
|
||||||
* Names filtering is done on the frontend
|
* Names filtering is done on the frontend
|
||||||
* Results will be cached in a single file
|
* 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',
|
'SELECT' => 'u.username_clean, u.username, u.user_id',
|
||||||
'FROM' => [
|
'FROM' => [
|
||||||
USERS_TABLE => 'u',
|
USERS_TABLE => 'u',
|
||||||
|
|
|
@ -15,18 +15,38 @@ namespace phpbb\mention\source;
|
||||||
|
|
||||||
class topic extends base_user
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function query($keyword, $topic_id)
|
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
|
* For optimization purposes all users are returned regardless of the keyword
|
||||||
* Names filtering is done on the frontend
|
* Names filtering is done on the frontend
|
||||||
* Results will be cached on a per-topic basis
|
* Results will be cached on a per-topic basis
|
||||||
*/
|
*/
|
||||||
$query = $this->db->sql_build_query('SELECT', [
|
$query = $this->db->sql_build_query('SELECT', [
|
||||||
'SELECT' => 'u.username, u.user_id',
|
'SELECT' => 'u.username, u.user_id, t.topic_poster',
|
||||||
'FROM' => [
|
'FROM' => [
|
||||||
USERS_TABLE => 'u',
|
USERS_TABLE => 'u',
|
||||||
],
|
],
|
||||||
|
@ -34,7 +54,11 @@ class topic extends base_user
|
||||||
[
|
[
|
||||||
'FROM' => [POSTS_TABLE => 'p'],
|
'FROM' => [POSTS_TABLE => 'p'],
|
||||||
'ON' => 'u.user_id = p.poster_id'
|
'ON' => 'u.user_id = p.poster_id'
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'FROM' => [TOPICS_TABLE => 't'],
|
||||||
|
'ON' => 't.topic_id = p.topic_id'
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'WHERE' => 'p.topic_id = ' . $topic_id . '
|
'WHERE' => 'p.topic_id = ' . $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]),
|
||||||
|
|
|
@ -15,19 +15,31 @@ namespace phpbb\mention\source;
|
||||||
|
|
||||||
class user extends base_user
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function query($keyword, $topic_id)
|
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', [
|
$query = $this->db->sql_build_query('SELECT', [
|
||||||
'SELECT' => 'u.username_clean, u.username, u.user_id',
|
'SELECT' => 'u.username_clean, u.username, u.user_id',
|
||||||
'FROM' => [
|
'FROM' => [
|
||||||
USERS_TABLE => 'u',
|
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'
|
'ORDER_BY' => 'u.user_lastvisit DESC'
|
||||||
]);
|
]);
|
||||||
return $query;
|
return $query;
|
||||||
|
|
Loading…
Add table
Reference in a new issue