aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorShitiz Garg <mail@dragooon.net>2014-06-26 03:07:45 +0530
committerShitiz Garg <mail@dragooon.net>2014-06-27 17:48:37 +0530
commit2cf4a4f6fe74ee6d774956113570d6ed7c5246cc (patch)
tree33197bd3ede53b63997c2b55a84569153ae60d58 /phpBB
parentc1df2ce62a62517e840ff30fa11a6cffb84396bc (diff)
downloadforums-2cf4a4f6fe74ee6d774956113570d6ed7c5246cc.tar
forums-2cf4a4f6fe74ee6d774956113570d6ed7c5246cc.tar.gz
forums-2cf4a4f6fe74ee6d774956113570d6ed7c5246cc.tar.bz2
forums-2cf4a4f6fe74ee6d774956113570d6ed7c5246cc.tar.xz
forums-2cf4a4f6fe74ee6d774956113570d6ed7c5246cc.zip
[ticket/12759] Cache all lang_options in lang_helper instead
PHPBB3-12759
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/includes/ucp/ucp_pm_viewmessage.php2
-rw-r--r--phpBB/memberlist.php7
-rw-r--r--phpBB/phpbb/profilefields/lang_helper.php63
-rw-r--r--phpBB/phpbb/profilefields/manager.php27
-rw-r--r--phpBB/phpbb/profilefields/type/type_bool.php4
-rw-r--r--phpBB/phpbb/profilefields/type/type_dropdown.php6
-rw-r--r--phpBB/viewtopic.php8
7 files changed, 35 insertions, 82 deletions
diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php
index 9e26b3b129..f42200d249 100644
--- a/phpBB/includes/ucp/ucp_pm_viewmessage.php
+++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php
@@ -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
diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php
index e42c7fab0c..63541dbee6 100644
--- a/phpBB/memberlist.php
+++ b/phpBB/memberlist.php
@@ -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...
diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php
index 86c4e6ff72..2e353722b2 100644
--- a/phpBB/phpbb/profilefields/lang_helper.php
+++ b/phpBB/phpbb/profilefields/lang_helper.php
@@ -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)
- {
- 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;
- }
- }
- else
+ foreach ($lang_options as $num => $var)
{
- if (is_array($field_id))
+ if (!isset($this->options_lang[$field_id]))
{
- $field_id = array_map('intval', array_unique($field_id));
+ $this->options_lang[$field_id] = array();
}
- else
+ if (!isset($this->options_lang[$field_id][$lang_id]))
{
- $field_id = array((int) $field_id);
+ $this->options_lang[$field_id][$lang_id] = array();
}
+ $this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
+ }
+ }
- $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);
}
/**
diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php
index 251899146b..bd08580431 100644
--- a/phpBB/phpbb/profilefields/manager.php
+++ b/phpBB/phpbb/profilefields/manager.php
@@ -368,33 +368,6 @@ class manager
}
/**
- * 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
*
* @param array $profile_row Array with users profile field data
diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php
index 86e480f6b3..b9a7f93b85 100644
--- a/phpBB/phpbb/profilefields/type/type_bool.php
+++ b/phpBB/phpbb/profilefields/type/type_bool.php
@@ -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']);
diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php
index 5ecbf4e167..7780f70d64 100644
--- a/phpBB/phpbb/profilefields/type/type_dropdown.php
+++ b/phpBB/phpbb/profilefields/type/type_dropdown.php
@@ -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;
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index 760b4e5c87..d87f7de2b0 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -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