1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-20 08:05:19 +01:00

[ticket/12759] Cache all lang_options in lang_helper instead

PHPBB3-12759
This commit is contained in:
Shitiz Garg 2014-06-26 03:07:45 +05:30
parent c1df2ce62a
commit 2cf4a4f6fe
7 changed files with 37 additions and 84 deletions

View File

@ -68,8 +68,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
$cp = $phpbb_container->get('profilefields.manager');
$profile_fields = $cp->grab_profile_fields_data($author_id);
$cp->cache_profile_fields_lang_options($profile_fields[$author_id]);
}
// Assign TO/BCC Addresses to template

View File

@ -1382,7 +1382,6 @@ switch ($mode)
{
// Grab all profile fields from users in id cache for later use - similar to the poster cache
$profile_fields_cache = $cp->grab_profile_fields_data($user_list);
$profile_rows = array();
// Filter the fields we don't want to show
foreach ($profile_fields_cache as $user_id => $user_profile_fields)
@ -1393,14 +1392,8 @@ switch ($mode)
{
unset($profile_fields_cache[$user_id][$field_ident]);
}
else
{
$profile_rows[] = $profile_field;
}
}
}
$cp->cache_profile_fields_lang_options($profile_rows);
}
// If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...

View File

@ -49,55 +49,50 @@ class lang_helper
}
/**
* Get language entries for options and store them here for later use
* Loads preview options into language entries for options
*
* @param mixed $field_id Can be an int or an array of int for multiple field IDs
* @param int $field_id
* @param int $lang_id
* @param mixed $preview_options If set to not false, $field_id cannot be an array
* @param mixed $preview_options
*/
public function get_option_lang($field_id, $lang_id, $preview_options)
public function load_preview_options($field_id, $lang_id, $preview_options)
{
if ($preview_options !== false)
{
$lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options;
$lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options;
foreach ($lang_options as $num => $var)
foreach ($lang_options as $num => $var)
{
if (!isset($this->options_lang[$field_id]))
{
if (!isset($this->options_lang[$field_id]))
{
$this->options_lang[$field_id] = array();
}
if (!isset($this->options_lang[$field_id][$lang_id]))
{
$this->options_lang[$field_id][$lang_id] = array();
}
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
$this->options_lang[$field_id] = array();
}
if (!isset($this->options_lang[$field_id][$lang_id]))
{
$this->options_lang[$field_id][$lang_id] = array();
}
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
}
else
{
if (is_array($field_id))
{
$field_id = array_map('intval', array_unique($field_id));
}
else
{
$field_id = array((int) $field_id);
}
}
$sql = 'SELECT field_id, option_id, lang_value
/**
* Fetches language entries for options from DB
*
* @param int $lang_id
*/
public function load_option_lang($lang_id)
{
$sql = 'SELECT field_id, option_id, lang_value
FROM ' . $this->language_table . '
WHERE ' . $this->db->sql_in_set('field_id', $field_id) . '
AND lang_id = ' . (int) $lang_id . "
WHERE lang_id = ' . (int) $lang_id . "
ORDER BY option_id";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
}
$this->db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
}
$this->db->sql_freeresult($result);
}
/**

View File

@ -367,33 +367,6 @@ class manager
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
*

View File

@ -155,7 +155,7 @@ class type_bool extends type_base
if (!$this->lang_helper->is_set($field_id, $lang_id))
{
$this->lang_helper->get_option_lang($field_id, $lang_id, false);
$this->lang_helper->load_option_lang($lang_id);
}
if (!$field_value && $field_data['field_show_novalue'])
@ -203,7 +203,7 @@ class type_bool extends type_base
{
if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
{
$this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
$this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
}
$options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']);

View File

@ -135,7 +135,7 @@ class type_dropdown extends type_base
// retrieve option lang data if necessary
if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1))
{
$this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], false);
$this->lang_helper->load_option_lang($field_data['lang_id']);
}
if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value))
@ -160,7 +160,7 @@ class type_dropdown extends type_base
$lang_id = $field_data['lang_id'];
if (!$this->lang_helper->is_set($field_id, $lang_id))
{
$this->lang_helper->get_option_lang($field_id, $lang_id, false);
$this->lang_helper->load_option_lang($lang_id);
}
if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
@ -199,7 +199,7 @@ class type_dropdown extends type_base
if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
{
$this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
$this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
}
$profile_row['field_value'] = (int) $value;

View File

@ -1270,7 +1270,6 @@ 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.
$profile_fields_cache = array();
$profile_rows = array();
foreach ($profile_fields_tmp as $profile_user_id => $profile_fields)
{
$profile_fields_cache[$profile_user_id] = array();
@ -1279,15 +1278,10 @@ if ($config['load_cpf_viewtopic'])
if ($profile_field['data']['field_show_on_vt'])
{
$profile_fields_cache[$profile_user_id][$used_ident] = $profile_field;
$profile_rows[] = $profile_field;
}
}
}
// Cache the language options for optimisation
$cp->cache_profile_fields_lang_options($profile_rows);
unset($profile_fields_tmp, $profile_rows);
unset($profile_fields_tmp);
}
// Generate online information for user