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

[ticket/13713] Remove mention colors to reduce the cache size

PHPBB3-13713
This commit is contained in:
lavigor
2018-09-15 12:26:06 +03:00
committed by Marc Alexander
parent 149d0aa5d3
commit b84c10733b
4 changed files with 3 additions and 79 deletions

View File

@@ -42,11 +42,6 @@ class mention_helper
*/
protected $group_profile_url;
/**
* @var array Array of users' and groups' colours for each cached ID
*/
protected $cached_colours = [];
/**
* @var array Array of group IDs allowed to be mentioned by current user
*/
@@ -70,63 +65,6 @@ class mention_helper
$this->group_profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=group&g={ID}', false);
}
/**
* Returns SQL query data for colour SELECT request
*
* @param string $type Name type ('u' for users, 'g' for groups)
* @return array Array of SQL SELECT query data for extracting colours for names
*/
protected function get_colours_sql($type)
{
switch ($type)
{
default:
case 'u':
return [
'SELECT' => 'u.user_colour as colour, u.user_id as id',
'FROM' => [
USERS_TABLE => 'u',
],
'WHERE' => $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]),
];
case 'g':
return [
'SELECT' => 'g.group_colour as colour, g.group_id as id',
'FROM' => [
GROUPS_TABLE => 'g',
],
];
}
}
/**
* Caches colours of users and groups
*/
protected function cache_colours()
{
if (count($this->cached_colours) > 0)
{
return;
}
$types = ['u', 'g'];
foreach ($types as $type)
{
$this->cached_colours[$type] = [];
$query = $this->db->sql_build_query('SELECT', $this->get_colours_sql($type));
$result = $this->db->sql_query($query, 300);
while ($row = $this->db->sql_fetchrow($result))
{
$this->cached_colours[$type][$row['id']] = $row['colour'];
}
$this->db->sql_freeresult($result);
}
}
/**
* Inject dynamic metadata into MENTION tags in given XML
*
@@ -140,8 +78,6 @@ class mention_helper
'g' => $this->group_profile_url,
];
$this->cache_colours();
return TextFormatterUtils::replaceAttributes(
$xml,
'MENTION',
@@ -153,11 +89,6 @@ class mention_helper
$id = $attributes['id'];
$attributes['profile_url'] = str_replace('{ID}', $id, $profile_urls[$type]);
if (!empty($this->cached_colours[$type][$id]))
{
$attributes['color'] = $this->cached_colours[$type][$id];
}
}
return $attributes;