[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
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
4 changed files with 3 additions and 79 deletions

View file

@ -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>

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;

View file

@ -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>

View file

@ -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&amp;u=3',
'color="00FF00"',
],
[
'<r><MENTION id="3" type="g"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
'mode=group&amp;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()