[ticket/12759] Cache the lang options earlier

Previously it would re-run on every post

PHPBB3-12759
This commit is contained in:
Shitiz Garg 2014-06-22 18:55:35 +05:30
parent 6cf6ec3354
commit aebe03f88c
2 changed files with 35 additions and 20 deletions

View file

@ -367,6 +367,34 @@ class manager
return $user_fields; return $user_fields;
} }
/**
* Cache user's profile fields' language options
* @param array $profile_row Array with users profile field data
* @return void
*/
public function cache_profile_fields_lang_options($profile_row)
{
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);
}
}
}
/** /**
* Assign the user's profile fields data to the template * Assign the user's profile fields data to the template
* *
@ -393,25 +421,6 @@ class manager
$vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); $vars = array('profile_row', 'tpl_fields', 'use_contact_fields');
extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars))); 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) foreach ($profile_row as $ident => $ident_ary)
{ {
$profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $profile_field = $this->type_collection[$ident_ary['data']['field_type']];

View file

@ -1270,6 +1270,7 @@ if ($config['load_cpf_viewtopic'])
// filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs. // filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs.
$profile_fields_cache = array(); $profile_fields_cache = array();
$profile_rows = array();
foreach ($profile_fields_tmp as $profile_user_id => $profile_fields) foreach ($profile_fields_tmp as $profile_user_id => $profile_fields)
{ {
$profile_fields_cache[$profile_user_id] = array(); $profile_fields_cache[$profile_user_id] = array();
@ -1278,10 +1279,15 @@ if ($config['load_cpf_viewtopic'])
if ($profile_field['data']['field_show_on_vt']) if ($profile_field['data']['field_show_on_vt'])
{ {
$profile_fields_cache[$profile_user_id][$used_ident] = $profile_field; $profile_fields_cache[$profile_user_id][$used_ident] = $profile_field;
$profile_rows[] = $profile_field;
} }
} }
} }
unset($profile_fields_tmp);
// Cache the language options for optimisation
$cp->cache_profile_fields_lang_options($profile_rows);
unset($profile_fields_tmp, $profile_rows);
} }
// Generate online information for user // Generate online information for user