[ticket/494] Cache more queries on portal page

B3P-494
This commit is contained in:
Marc Alexander
2015-03-03 15:25:22 +01:00
parent a699a92e31
commit 1e405e9d91
13 changed files with 55 additions and 62 deletions

View File

@@ -70,32 +70,24 @@ function set_portal_config($config_name, $config_value)
}
/**
* Get portal modules
*/
* Get portal modules
*/
function obtain_portal_modules()
{
global $db, $cache, $portal_modules;
global $db;
if (($portal_modules = $cache->get('portal_modules')) === false || defined('DEBUG'))
$portal_modules = array();
$sql = 'SELECT *
FROM ' . PORTAL_MODULES_TABLE . '
ORDER BY module_order ASC';
$result = $db->sql_query($sql, 3600);
while ($row = $db->sql_fetchrow($result))
{
$portal_modules = $portal_cached_modules = array();
$sql = 'SELECT *
FROM ' . PORTAL_MODULES_TABLE . '
ORDER BY module_order ASC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$portal_cached_modules[] = $row;
$portal_modules[] = $row;
}
$db->sql_freeresult($result);
$cache->put('portal_modules', $portal_cached_modules);
$portal_modules[] = $row;
}
$db->sql_freeresult($result);
return $portal_modules;
}

View File

@@ -225,7 +225,7 @@ class announcements extends module_base
AND topic_moved_id = 0
' . $post_time . '
' . $str_where;
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 300);
$total_announcements = (int) $this->db->sql_fetchfield('num_topics');
$this->db->sql_freeresult($result);
}

View File

@@ -53,10 +53,10 @@ class attachments extends module_base
/** @var \phpbb\request\request */
protected $request;
/** @var \phpbb\template */
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var string PHP file extension */
@@ -74,8 +74,8 @@ class attachments extends module_base
* @param \phpbb\auth\auth $auth phpBB auth service
* @param \phpbb\config\config $config phpBB config
* @param \board3\portal\includes\modules_helper $helper Modules helper
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver $db Database driver
* @param \phpbb\template\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db Database driver
* @param \phpbb\request\request $request phpBB request
* @param string $phpEx php file extension
* @param string $phpbb_root_path phpBB root path
@@ -281,7 +281,7 @@ class attachments extends module_base
' . $where . '
ORDER BY
filetime ' . ((!$this->config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC';
$result = $this->db->sql_query_limit($sql, $this->config['board3_attachments_number_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_attachments_number_' . $module_id], 0, 600);
while ($row = $this->db->sql_fetchrow($result))
{

View File

@@ -119,7 +119,7 @@ class birthday_list extends module_base
'ORDER BY' => $order_by,
);
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 3600);
$today = sprintf('%2d-%2d-', $now['mday'], $now['mon']);
while ($row = $this->db->sql_fetchrow($result))

View File

@@ -49,10 +49,10 @@ class latest_bots extends module_base
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\template */
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\user */
@@ -62,8 +62,8 @@ class latest_bots extends module_base
* Construct a latest bots object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\db\driver $db phpBB db driver
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db phpBB db driver
* @param \phpbb\template\template $template phpBB template
* @param \phpbb\user $user phpBB user object
*/
public function __construct($config, $db, $template, $user)
@@ -85,7 +85,7 @@ class latest_bots extends module_base
WHERE user_type = ' . USER_IGNORE . '
AND user_lastvisit > 0
ORDER BY user_lastvisit DESC';
$result = $this->db->sql_query_limit($sql, $this->config['board3_last_visited_bots_number_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_last_visited_bots_number_' . $module_id], 0, 600);
$show_module = false;

View File

@@ -44,10 +44,10 @@ class latest_members extends module_base
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\template */
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\user */
@@ -57,8 +57,8 @@ class latest_members extends module_base
* Construct a latest_members object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\db\driver $db phpBB db driver
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db phpBB db driver
* @param \phpbb\template\template $template phpBB template
* @param \phpbb\user $user phpBB user object
*/
public function __construct($config, $db, $template, $user)
@@ -79,7 +79,7 @@ class latest_members extends module_base
WHERE user_type <> ' . USER_IGNORE . '
AND user_inactive_time = 0
ORDER BY user_regdate DESC';
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_last_member_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_last_member_' . $module_id], 0, 600);
while(($row = $this->db->sql_fetchrow($result)) && ($row['username']))
{

View File

@@ -118,7 +118,7 @@ class leaders extends module_base
AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $this->user->data['user_id'] . ')
ORDER BY g.group_name ASC';
}
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 600);
while ($row = $this->db->sql_fetchrow($result))
{
@@ -144,7 +144,7 @@ class leaders extends module_base
ug.user_id = u.user_id
AND '. $this->db->sql_in_set('ug.group_id', $legends) . '
ORDER BY u.username_clean ASC';
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 600);
while ($row = $this->db->sql_fetchrow($result))
{
@@ -201,7 +201,7 @@ class leaders extends module_base
'ORDER_BY' => 'g.group_name ASC, u.username_clean ASC'
));
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 600);
while ($row = $this->db->sql_fetchrow($result))
{

View File

@@ -218,7 +218,7 @@ class news extends module_base
AND topic_visibility = ' . ITEM_APPROVED . '
AND topic_moved_id = 0
' . $str_where;
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 300);
$total_news = (int) $this->db->sql_fetchfield('num_topics');
$this->db->sql_freeresult($result);
}

View File

@@ -121,7 +121,7 @@ class recent extends module_base
$forum_sql = ' AND ' . $this->db->sql_in_set('t.forum_id', $forum_ary, true);
}
$result = $this->db->sql_query_limit($sql, 1);
$result = $this->db->sql_query_limit($sql, 1, 0, 600);
$g_forum_id = (int) $this->db->sql_fetchfield('forum_id');
$this->db->sql_freeresult($result);
@@ -134,9 +134,9 @@ class recent extends module_base
AND topic_visibility = ' . ITEM_APPROVED . '
AND (topic_type = ' . POST_ANNOUNCE . ' OR topic_type = ' . POST_GLOBAL . ')
AND topic_moved_id = 0
' . $sql_where . '' . $forum_sql . '
' . $sql_where . $forum_sql . '
ORDER BY topic_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0 , 600);
while(($row = $this->db->sql_fetchrow($result)) && ($row['topic_title']))
{
@@ -160,9 +160,9 @@ class recent extends module_base
WHERE topic_visibility = ' . ITEM_APPROVED . '
AND topic_posts_approved >' . $this->config['hot_threshold'] . '
AND topic_moved_id = 0
' . $sql_where . '' . $forum_sql . '
' . $sql_where . $forum_sql . '
ORDER BY topic_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 600);
while(($row = $this->db->sql_fetchrow($result)) && ($row['topic_title']))
{
@@ -187,9 +187,9 @@ class recent extends module_base
AND topic_visibility = ' . ITEM_APPROVED . '
AND topic_type = ' . POST_NORMAL . '
AND topic_moved_id = 0
' . $sql_where . '' . $forum_sql . '
' . $sql_where . $forum_sql . '
ORDER BY topic_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_max_topics_' . $module_id], 0, 600);
while(($row = $this->db->sql_fetchrow($result)) && ($row['topic_title']))
{

View File

@@ -90,7 +90,7 @@ class stylechanger extends module_base
FROM ' . STYLES_TABLE . '
WHERE style_active = 1
ORDER BY LOWER(style_name) ASC';
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 3600);
while ($row = $this->db->sql_fetchrow($result))
{
$style = $this->request->variable('style', 0);
@@ -113,7 +113,7 @@ class stylechanger extends module_base
// Assign specific vars
$this->template->assign_vars(array(
'S_STYLE_OPTIONS' => ($this->config['override_user_style'] || $style_count < 2) ? '' : style_select($this->user->data['user_style']),
'S_STYLE_OPTIONS' => ($this->config['override_user_style'] || $style_count < 2) ? '' : $style_select,
));
return 'stylechanger_side.html';

View File

@@ -44,10 +44,10 @@ class topposters extends module_base
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\template */
/** @var \phpbb\template\template */
protected $template;
/** @var string PHP file extension */
@@ -60,8 +60,8 @@ class topposters extends module_base
* Construct a topposers object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\db\driver $db phpBB db driver
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db phpBB db driver
* @param \phpbb\template\template $template phpBB template
* @param string $phpbb_root_path phpBB root path
* @param string $phpEx php file extension
*/
@@ -85,7 +85,7 @@ class topposters extends module_base
AND user_posts <> 0
AND username <> ''
ORDER BY user_posts DESC";
$result = $this->db->sql_query_limit($sql, $this->config['board3_topposters_' . $module_id]);
$result = $this->db->sql_query_limit($sql, $this->config['board3_topposters_' . $module_id], 0, 600);
while (($row = $this->db->sql_fetchrow($result)))
{

View File

@@ -125,13 +125,13 @@ class user_menu extends module_base
$m_approve_fid_sql = ' AND p.post_visibility = 1';
}
$sql = 'SELECT COUNT(distinct t.topic_id) as total
$sql = 'SELECT COUNT(DISTINCT t.topic_id) as total
FROM ' . TOPICS_TABLE . ' t
WHERE t.topic_last_post_time > ' . $this->user->data['user_lastvisit'] . '
AND t.topic_moved_id = 0
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 600);
$new_posts_count = (int) $this->db->sql_fetchfield('total');
$this->db->sql_freeresult($result);

View File

@@ -19,7 +19,7 @@ class fetch_posts
/**
* phpBB cache
* @var \phpbb\cache\driver
* @var \phpbb\cache\driver\driver_interface
*/
protected $cache;
@@ -31,7 +31,7 @@ class fetch_posts
/**
* phpBB db driver
* @var \phpbb\db\driver_interface
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
@@ -263,13 +263,14 @@ class fetch_posts
$sql_array['SELECT'] .= ', tp.topic_posted';
$sql = $this->db->sql_build_query('SELECT', $sql_array);
// Cache queries for 10 minutes
if ($number_of_posts != 0)
{
$result = $this->db->sql_query_limit($sql, $number_of_posts, $start);
$result = $this->db->sql_query_limit($sql, $number_of_posts, $start, 600);
}
else
{
$result = $this->db->sql_query($sql);
$result = $this->db->sql_query($sql, 600);
}
return $result;