1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-13 12:22:03 +02:00

[ticket/12759] Cache lang options for all fields while displaying

Previously these would be fetched one field at one time, causing a large
number of queries in case there were large number of custom profile fields
and/or unique number of users in areas such as viewing topics. Resolve this
by caching them at once when generating data for displaying them in templates.

PHPBB3-12759
This commit is contained in:
Shitiz Garg 2014-06-22 18:13:01 +05:30
parent 6d23cc3a0e
commit 6cf6ec3354
2 changed files with 29 additions and 1 deletions

View File

@ -5,6 +5,7 @@ services:
- @auth
- @dbal.conn
- @dispatcher
- @profilefields.lang_helper
- @request
- @template
- @profilefields.type_collection

View File

@ -36,6 +36,12 @@ class manager
*/
protected $dispatcher;
/**
* Profile fields language helper
* @var \phpbb\profilefields\lang_helper
*/
protected $lang_helper;
/**
* Request object
* @var \phpbb\request\request
@ -74,6 +80,7 @@ class manager
* @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\db\driver\driver_interface $db Database object
* @param \phpbb\event\dispatcher $dispatcher Event dispatcher object
* @param \phpbb\profilefields\lang_helper $lang_helper Language helper object
* @param \phpbb\request\request $request Request object
* @param \phpbb\template\template $template Template object
* @param \phpbb\di\service_collection $type_collection
@ -82,11 +89,12 @@ class manager
* @param string $fields_language_table
* @param string $fields_data_table
*/
public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
{
$this->auth = $auth;
$this->db = $db;
$this->dispatcher = $dispatcher;
$this->lang_helper = $lang_helper;
$this->request = $request;
$this->template = $template;
$this->type_collection = $type_collection;
@ -385,6 +393,25 @@ class manager
$vars = array('profile_row', 'tpl_fields', 'use_contact_fields');
extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars)));
if (!empty($profile_row))
{
$field_ids = array();
foreach ($profile_row as $ident_ary)
{
if (empty($field_ids[$ident_ary['data']['lang_id']]))
{
$field_ids[$ident_ary['data']['lang_id']] = array();
}
$field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id'];
}
foreach ($field_ids as $lang => $fields)
{
$this->lang_helper->get_option_lang($fields, $lang, false);
}
}
foreach ($profile_row as $ident => $ident_ary)
{
$profile_field = $this->type_collection[$ident_ary['data']['field_type']];