1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01:00

[feature/soft-delete] Simplification part2: user can see all item visibilities

If the user can see all visibilities, we can simply leave out the query part,
instead of adding a bunch of ANDs.

PHPBB3-9657
This commit is contained in:
Joas Schilling 2012-08-29 22:12:33 +02:00
parent 44ed05f567
commit a1e0690b6b
5 changed files with 36 additions and 14 deletions

View File

@ -779,6 +779,8 @@ class phpbb_feed_overall extends phpbb_feed_post_base
return false; return false;
} }
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', array(), 'p.');
// Get the actual data // Get the actual data
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, ' . 'SELECT' => 'f.forum_id, f.forum_name, ' .
@ -795,7 +797,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
), ),
), ),
'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
AND ' . phpbb_content_visibility::get_visibility_sql('post', array(), 'p.') . ' ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . '
AND p.post_time >= ' . $min_post_time . ' AND p.post_time >= ' . $min_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',
@ -885,14 +887,14 @@ class phpbb_feed_forum extends phpbb_feed_post_base
{ {
global $auth, $db; global $auth, $db;
$m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false; $sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $this->forum_id);
// Determine topics with recent activity // Determine topics with recent activity
$sql = 'SELECT topic_id, topic_last_post_time $sql = 'SELECT topic_id, topic_last_post_time
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $this->forum_id . ' WHERE forum_id = ' . $this->forum_id . '
AND topic_moved_id = 0 AND topic_moved_id = 0
AND ' . phpbb_content_visibility::get_visibility_sql('topic', $this->forum_id) . ' ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . '
ORDER BY topic_last_post_time DESC'; 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);
@ -911,6 +913,8 @@ class phpbb_feed_forum extends phpbb_feed_post_base
return false; return false;
} }
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.');
$this->sql = array( $this->sql = array(
'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, 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',
@ -919,7 +923,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base
USERS_TABLE => 'u', USERS_TABLE => 'u',
), ),
'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
AND ' . phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . ' ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . '
AND p.post_time >= ' . $min_post_time . ' AND p.post_time >= ' . $min_post_time . '
AND p.poster_id = u.user_id', AND p.poster_id = u.user_id',
'ORDER_BY' => 'p.post_time DESC', 'ORDER_BY' => 'p.post_time DESC',
@ -1017,6 +1021,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base
{ {
global $auth, $db; global $auth, $db;
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.');
$this->sql = array( $this->sql = array(
'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, 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',
@ -1025,7 +1030,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base
USERS_TABLE => 'u', USERS_TABLE => 'u',
), ),
'WHERE' => 'p.topic_id = ' . $this->topic_id . ' 'WHERE' => 'p.topic_id = ' . $this->topic_id . '
AND ' . phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . ' ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . '
AND p.poster_id = u.user_id', AND p.poster_id = u.user_id',
'ORDER_BY' => 'p.post_time DESC', 'ORDER_BY' => 'p.post_time DESC',
); );

View File

@ -43,9 +43,15 @@ class phpbb_content_visibility
{ {
$status_ary[] = ITEM_DELETED; $status_ary[] = ITEM_DELETED;
if (sizeof($status_ary) == 3)
{
// The user can see all types, so we simplify this to an empty string,
// as we don't need to restrict anything on the query.
return '';
}
// If the user has m_restore, the rest of the function will not // If the user has m_restore, the rest of the function will not
// make more content visible, so we can return the query here. // make more content visible, so we can return the query here.
// This avoids one OR in all queries
return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary);
} }

View File

@ -1855,7 +1855,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti
// Handle update of unapproved topics info. // Handle update of unapproved topics info.
// Only update for moderators having m_approve permission for the forum. // Only update for moderators having m_approve permission for the forum.
$sql_update_unapproved = ($auth->acl_get('m_approve', $forum_id)) ? '': 'AND t.topic_approved = 1'; $sql_update_unapproved = phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.');
$sql_update_unapproved = ($sql_update_unapproved) ? ' AND ' . $sql_update_unapproved : '';
// Check the forum for any left unread topics. // Check the forum for any left unread topics.
// If there are none, we mark the forum as read. // If there are none, we mark the forum as read.

View File

@ -234,6 +234,7 @@ gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $
if ($sort_days) if ($sort_days)
{ {
$min_post_time = time() - ($sort_days * 86400); $min_post_time = time() - ($sort_days * 86400);
$sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $forum_id);
$sql = 'SELECT COUNT(topic_id) AS num_topics $sql = 'SELECT COUNT(topic_id) AS num_topics
FROM ' . TOPICS_TABLE . " FROM ' . TOPICS_TABLE . "
@ -241,7 +242,7 @@ if ($sort_days)
AND (topic_last_post_time >= $min_post_time AND (topic_last_post_time >= $min_post_time
OR topic_type = " . POST_ANNOUNCE . ' OR topic_type = " . POST_ANNOUNCE . '
OR topic_type = ' . POST_GLOBAL . ') OR topic_type = ' . POST_GLOBAL . ')
AND ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id); ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '');
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$topics_count = (int) $db->sql_fetchfield('num_topics'); $topics_count = (int) $db->sql_fetchfield('num_topics');
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -353,7 +354,8 @@ $sql_array = array(
'LEFT_JOIN' => array(), 'LEFT_JOIN' => array(),
); );
$sql_approved = 'AND ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); $sql_approved = phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.');
$sql_approved = ($sql_approved) ? ' AND ' . $sql_approved : '';
if ($user->data['is_registered']) if ($user->data['is_registered'])
{ {

View File

@ -79,11 +79,12 @@ if ($view && !$post_id)
$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
$topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0; $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0;
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id);
$sql = 'SELECT post_id, topic_id, forum_id $sql = 'SELECT post_id, topic_id, forum_id
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id WHERE topic_id = $topic_id
AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id) . " " . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . "
AND post_time > $topic_last_read AND post_time > $topic_last_read
AND forum_id = $forum_id AND forum_id = $forum_id
ORDER BY post_time ASC"; ORDER BY post_time ASC";
@ -132,12 +133,14 @@ if ($view && !$post_id)
} }
else else
{ {
$sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $row['forum_id']);
$sql = 'SELECT topic_id, forum_id $sql = 'SELECT topic_id, forum_id
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $row['forum_id'] . " WHERE forum_id = ' . $row['forum_id'] . "
AND topic_moved_id = 0 AND topic_moved_id = 0
AND topic_last_post_time $sql_condition {$row['topic_last_post_time']} AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
AND" . phpbb_content_visibility::get_visibility_sql('topic', $row['forum_id']) . " " . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . "
ORDER BY topic_last_post_time $sql_ordering"; ORDER BY topic_last_post_time $sql_ordering";
$result = $db->sql_query_limit($sql, 1); $result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
@ -274,10 +277,12 @@ if ($post_id)
} }
else else
{ {
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.');
$sql = 'SELECT COUNT(p.post_id) AS prev_posts $sql = 'SELECT COUNT(p.post_id) AS prev_posts
FROM ' . POSTS_TABLE . " p FROM ' . POSTS_TABLE . " p
WHERE p.topic_id = {$topic_data['topic_id']} WHERE p.topic_id = {$topic_data['topic_id']}
AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.'); " . (($sql_visibility) ? ' AND ' . $sql_visibility : '');
if ($sort_dir == 'd') if ($sort_dir == 'd')
{ {
@ -403,12 +408,13 @@ gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $
if ($sort_days) if ($sort_days)
{ {
$min_post_time = time() - ($sort_days * 86400); $min_post_time = time() - ($sort_days * 86400);
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id);
$sql = 'SELECT COUNT(post_id) AS num_posts $sql = 'SELECT COUNT(post_id) AS num_posts
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id WHERE topic_id = $topic_id
AND post_time >= $min_post_time AND post_time >= $min_post_time
AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); " . (($sql_visibility) ? ' AND ' . $sql_visibility : '');
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$total_posts = (int) $db->sql_fetchfield('num_posts'); $total_posts = (int) $db->sql_fetchfield('num_posts');
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -942,10 +948,12 @@ $bbcode_bitfield = '';
$i = $i_total = 0; $i = $i_total = 0;
// Go ahead and pull all data for this topic // Go ahead and pull all data for this topic
$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.');
$sql = 'SELECT p.post_id $sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . " FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . "
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.') . " " . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . "
" . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . " " . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . "
$limit_posts_time $limit_posts_time
ORDER BY $sql_sort_order"; ORDER BY $sql_sort_order";