mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/13713] Remove mention colors to reduce the cache size
PHPBB3-13713
This commit is contained in:
parent
149d0aa5d3
commit
b84c10733b
4 changed files with 3 additions and 79 deletions
|
@ -87,7 +87,6 @@ class factory implements \phpbb\textformatter\cache_interface
|
|||
'mention' =>
|
||||
"[MENTION={PARSE=/^(?<type>[ug]):(?<id>\d+)$/}
|
||||
profile_url={URL;optional;postFilter=#false}
|
||||
color={COLOR;optional}
|
||||
]{TEXT}[/MENTION]",
|
||||
'quote' =>
|
||||
"[QUOTE
|
||||
|
@ -136,9 +135,6 @@ class factory implements \phpbb\textformatter\cache_interface
|
|||
<xsl:when test="@profile_url">
|
||||
<a class="mention">
|
||||
<xsl:attribute name="href"><xsl:value-of select="@profile_url"/></xsl:attribute>
|
||||
<xsl:if test="@color">
|
||||
<xsl:attribute name="style">color: #<xsl:value-of select="@color"/>;</xsl:attribute>
|
||||
</xsl:if>
|
||||
<xsl:apply-templates/>
|
||||
</a>
|
||||
</xsl:when>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<value>3</value>
|
||||
<value>Hidden group we are a member of</value>
|
||||
<value>2</value>
|
||||
<value>FF0000</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
|
@ -53,7 +53,7 @@
|
|||
<value>test</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>00FF00</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
|
|
|
@ -82,12 +82,10 @@ class mention_helper_test extends phpbb_database_test_case
|
|||
[
|
||||
'<r><MENTION id="3" type="u"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION></r>',
|
||||
'mode=viewprofile&u=3',
|
||||
'color="00FF00"',
|
||||
],
|
||||
[
|
||||
'<r><MENTION id="3" type="g"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
|
||||
'mode=group&g=3',
|
||||
'color="FF0000"',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -95,11 +93,10 @@ class mention_helper_test extends phpbb_database_test_case
|
|||
/**
|
||||
* @dataProvider inject_metadata_data
|
||||
*/
|
||||
public function test_inject_metadata($incoming_xml, $expected_profile_substring, $expected_colour)
|
||||
public function test_inject_metadata($incoming_xml, $expected_profile_substring)
|
||||
{
|
||||
$result = $this->mention_helper->inject_metadata($incoming_xml);
|
||||
$this->assertContains($expected_profile_substring, $result);
|
||||
$this->assertContains($expected_colour, $result);
|
||||
}
|
||||
|
||||
public function get_mentioned_user_ids_data()
|
||||
|
|
Loading…
Add table
Reference in a new issue