Improve overall feed performance

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10400 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Andreas Fischer 2010-01-12 00:12:06 +00:00
parent f4aa5b7ac7
commit 2be2a2eb63

View file

@ -516,6 +516,13 @@ class phpbb_feed_base
return array_keys($auth->acl_getf('f_read')); return array_keys($auth->acl_getf('f_read'));
} }
function get_m_approve_forums()
{
global $auth;
return array_keys($auth->acl_getf('m_approve'));
}
function get_excluded_forums() function get_excluded_forums()
{ {
global $db, $cache; global $db, $cache;
@ -712,7 +719,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
{ {
function get_sql() function get_sql()
{ {
global $db; global $auth, $db;
$forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums());
if (empty($forum_ids)) if (empty($forum_ids))
@ -723,34 +730,39 @@ class phpbb_feed_overall extends phpbb_feed_post_base
// Add global forum id // Add global forum id
$forum_ids[] = 0; $forum_ids[] = 0;
// Determine post ids first for optimization // Forums with m_approve
$sql = 'SELECT post_id, post_time $m_approve_fids = array_keys($auth->acl_getf('m_approve'));
FROM ' . POSTS_TABLE . '
WHERE post_approved = 1 // Determine topics with recent activity
AND ' . $db->sql_in_set('forum_id', $forum_ids) . ' $sql = 'SELECT topic_id, topic_last_post_time
ORDER BY post_time DESC'; FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
AND (topic_approved = 1
OR ' . $db->sql_in_set('forum_id', $m_approve_fids) . ')
ORDER BY topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items); $result = $db->sql_query_limit($sql, $this->num_items);
$post_ids = array(); $topic_ids = array();
while ($post_id = (int) $db->sql_fetchfield('post_id')) $topic_last_post_time = PHP_INT_MAX;
while ($row = $db->sql_fetchrow())
{ {
$post_ids[] = $post_id; $topic_ids[] = (int) $row['topic_id'];
$topic_last_post_time = min($topic_last_post_time, (int) $row['topic_last_post_time']);
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
if (empty($post_ids)) if (empty($topic_ids))
{ {
return false; return false;
} }
// Get the actual data
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, f.forum_desc_options, ' . 'SELECT' => 'f.forum_id, f.forum_name, ' .
't.topic_id, t.topic_title, t.topic_time, t.topic_replies, t.topic_views, ' . 'p.post_id, p.topic_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'p.post_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'u.username, u.user_id', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
POSTS_TABLE => 'p', POSTS_TABLE => 'p',
TOPICS_TABLE => 't',
USERS_TABLE => 'u', USERS_TABLE => 'u',
), ),
'LEFT_JOIN' => array( 'LEFT_JOIN' => array(
@ -759,8 +771,10 @@ class phpbb_feed_overall extends phpbb_feed_post_base
'ON' => 'f.forum_id = p.forum_id', 'ON' => 'f.forum_id = p.forum_id',
), ),
), ),
'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . ' 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
AND t.topic_id = p.topic_id AND (p.post_approved = 1
OR ' . $db->sql_in_set('p.forum_id', $m_approve_fids) . ')
AND p.post_time >= ' . $topic_last_post_time . '
AND u.user_id = p.poster_id', AND u.user_id = p.poster_id',
'ORDER_BY' => 'p.post_time DESC', 'ORDER_BY' => 'p.post_time DESC',
); );