mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-09 12:58:52 +00:00
[ticket/13713] Optimize caching colours
PHPBB3-13713
This commit is contained in:
parent
59bf57eb73
commit
d91e3bd66a
1 changed files with 17 additions and 20 deletions
|
@ -74,10 +74,9 @@ class mention_helper
|
||||||
* Returns SQL query data for colour SELECT request
|
* Returns SQL query data for colour SELECT request
|
||||||
*
|
*
|
||||||
* @param string $type Name type ('u' for users, 'g' for groups)
|
* @param string $type Name type ('u' for users, 'g' for groups)
|
||||||
* @param array $ids Array of IDs
|
|
||||||
* @return array Array of SQL SELECT query data for extracting colours for names
|
* @return array Array of SQL SELECT query data for extracting colours for names
|
||||||
*/
|
*/
|
||||||
protected function get_colours_sql($type, $ids)
|
protected function get_colours_sql($type)
|
||||||
{
|
{
|
||||||
switch ($type)
|
switch ($type)
|
||||||
{
|
{
|
||||||
|
@ -88,9 +87,7 @@ class mention_helper
|
||||||
'FROM' => [
|
'FROM' => [
|
||||||
USERS_TABLE => 'u',
|
USERS_TABLE => 'u',
|
||||||
],
|
],
|
||||||
'WHERE' => 'u.user_id <> ' . ANONYMOUS . '
|
'WHERE' => $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]) . '
|
|
||||||
AND ' . $this->db->sql_in_set('u.user_id', $ids),
|
|
||||||
];
|
];
|
||||||
case 'g':
|
case 'g':
|
||||||
return [
|
return [
|
||||||
|
@ -98,25 +95,28 @@ class mention_helper
|
||||||
'FROM' => [
|
'FROM' => [
|
||||||
GROUPS_TABLE => 'g',
|
GROUPS_TABLE => 'g',
|
||||||
],
|
],
|
||||||
'WHERE' => $this->db->sql_in_set('g.group_id', $ids),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches colours for selected IDs of the specified type
|
* Caches colours of users and groups
|
||||||
*
|
|
||||||
* @param string $type Name type ('u' for users, 'g' for groups)
|
|
||||||
* @param array $ids Array of IDs
|
|
||||||
*/
|
*/
|
||||||
protected function get_colours($type, $ids)
|
protected function cache_colours()
|
||||||
{
|
{
|
||||||
$this->cached_colours[$type] = [];
|
if (count($this->cached_colours) > 0)
|
||||||
|
|
||||||
if (!empty($ids))
|
|
||||||
{
|
{
|
||||||
$query = $this->db->sql_build_query('SELECT', $this->get_colours_sql($type, $ids));
|
return;
|
||||||
$result = $this->db->sql_query($query);
|
}
|
||||||
|
|
||||||
|
$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))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
|
@ -140,10 +140,7 @@ class mention_helper
|
||||||
'g' => $this->group_profile_url,
|
'g' => $this->group_profile_url,
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: think about optimization for caching colors.
|
$this->cache_colours();
|
||||||
$this->cached_colours = [];
|
|
||||||
$this->get_colours('u', $this->get_mentioned_ids($xml, 'u'));
|
|
||||||
$this->get_colours('g', $this->get_mentioned_ids($xml, 'g'));
|
|
||||||
|
|
||||||
return TextFormatterUtils::replaceAttributes(
|
return TextFormatterUtils::replaceAttributes(
|
||||||
$xml,
|
$xml,
|
||||||
|
|
Loading…
Add table
Reference in a new issue