[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' =>
"[MENTION={PARSE=/^(?<type>[ug]):(?<id>\d+)$/} "[MENTION={PARSE=/^(?<type>[ug]):(?<id>\d+)$/}
profile_url={URL;optional;postFilter=#false} profile_url={URL;optional;postFilter=#false}
color={COLOR;optional}
]{TEXT}[/MENTION]", ]{TEXT}[/MENTION]",
'quote' => 'quote' =>
"[QUOTE "[QUOTE
@ -136,9 +135,6 @@ class factory implements \phpbb\textformatter\cache_interface
<xsl:when test="@profile_url"> <xsl:when test="@profile_url">
<a class="mention"> <a class="mention">
<xsl:attribute name="href"><xsl:value-of select="@profile_url"/></xsl:attribute> <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/> <xsl:apply-templates/>
</a> </a>
</xsl:when> </xsl:when>

View file

@ -42,11 +42,6 @@ class mention_helper
*/ */
protected $group_profile_url; 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 * @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); $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 * Inject dynamic metadata into MENTION tags in given XML
* *
@ -140,8 +78,6 @@ class mention_helper
'g' => $this->group_profile_url, 'g' => $this->group_profile_url,
]; ];
$this->cache_colours();
return TextFormatterUtils::replaceAttributes( return TextFormatterUtils::replaceAttributes(
$xml, $xml,
'MENTION', 'MENTION',
@ -153,11 +89,6 @@ class mention_helper
$id = $attributes['id']; $id = $attributes['id'];
$attributes['profile_url'] = str_replace('{ID}', $id, $profile_urls[$type]); $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; return $attributes;

View file

@ -24,7 +24,7 @@
<value>3</value> <value>3</value>
<value>Hidden group we are a member of</value> <value>Hidden group we are a member of</value>
<value>2</value> <value>2</value>
<value>FF0000</value> <value></value>
<value></value> <value></value>
</row> </row>
</table> </table>
@ -53,7 +53,7 @@
<value>test</value> <value>test</value>
<value>0</value> <value>0</value>
<value>0</value> <value>0</value>
<value>00FF00</value> <value></value>
<value></value> <value></value>
<value></value> <value></value>
</row> </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>', '<r><MENTION id="3" type="u"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION></r>',
'mode=viewprofile&amp;u=3', 'mode=viewprofile&amp;u=3',
'color="00FF00"',
], ],
[ [
'<r><MENTION id="3" type="g"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>', '<r><MENTION id="3" type="g"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
'mode=group&amp;g=3', 'mode=group&amp;g=3',
'color="FF0000"',
], ],
]; ];
} }
@ -95,11 +93,10 @@ class mention_helper_test extends phpbb_database_test_case
/** /**
* @dataProvider inject_metadata_data * @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); $result = $this->mention_helper->inject_metadata($incoming_xml);
$this->assertContains($expected_profile_substring, $result); $this->assertContains($expected_profile_substring, $result);
$this->assertContains($expected_colour, $result);
} }
public function get_mentioned_user_ids_data() public function get_mentioned_user_ids_data()