mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/soft-delete] Add get_visibility_sql_forums based on global
The resulting query is 4-times faster, as the forum_id IN () arrays are smaller and we need less AND/OR to build the hole query. The main difference between those two functions is, that this one takes an array of included ids and the _global one takes an array of excluded ids. PHPBB3-9657
This commit is contained in:
parent
df83f22b71
commit
1c043254c0
2 changed files with 50 additions and 7 deletions
|
@ -751,16 +751,11 @@ class phpbb_feed_overall extends phpbb_feed_post_base
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_approve forums
|
|
||||||
$fid_m_approve = $this->get_moderator_approve_forums();
|
|
||||||
$sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', $fid_m_approve) : '';
|
|
||||||
|
|
||||||
// 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 ' . $db->sql_in_set('forum_id', $forum_ids) . '
|
WHERE topic_moved_id = 0
|
||||||
AND topic_moved_id = 0
|
AND ' . phpbb_content_visibility::get_visibility_sql_forums('topic', $forum_ids) . '
|
||||||
AND ' . phpbb_content_visibility::get_visibility_sql_global('topic') . '
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,54 @@ class phpbb_content_visibility
|
||||||
return $clause;
|
return $clause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch visibility SQL for a set of forums
|
||||||
|
* @param $mode string - either "topic" or "post"
|
||||||
|
* @param $forum_ids - int array -
|
||||||
|
* @param $table_alias string - Table alias to prefix in SQL queries
|
||||||
|
* @return string with the appropriate combination SQL logic for topic/post_visibility
|
||||||
|
*/
|
||||||
|
static public function get_visibility_sql_forums($mode, $forum_ids = array(), $table_alias = '')
|
||||||
|
{
|
||||||
|
global $auth, $db, $user;
|
||||||
|
|
||||||
|
// users can always see approved posts
|
||||||
|
$where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED;
|
||||||
|
|
||||||
|
// in set notation: {approve_forums} = {m_approve} - {exclude_forums}
|
||||||
|
$approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true)));
|
||||||
|
if (sizeof($approve_forums))
|
||||||
|
{
|
||||||
|
// users can view unapproved topics in certain forums. specify them.
|
||||||
|
$where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . '
|
||||||
|
AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is exactly the same logic as for approve forums, above
|
||||||
|
$restore_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_restore', true)));
|
||||||
|
if (sizeof($restore_forums))
|
||||||
|
{
|
||||||
|
$where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . '
|
||||||
|
AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
// we also allow the user to view deleted posts he himself made
|
||||||
|
$user_restore_forums = array_diff(array_intersect($forum_ids, array_keys($auth->acl_getf('f_restore', true))), $restore_forums);
|
||||||
|
if (sizeof($user_restore_forums) && !sizeof($restore_forums))
|
||||||
|
{
|
||||||
|
$poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id';
|
||||||
|
|
||||||
|
// specify the poster ID, the visibility type, and the forums we're interested in
|
||||||
|
$where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . "
|
||||||
|
AND $table_alias{$mode}_visibility = " . ITEM_DELETED . "
|
||||||
|
AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
$where_sql .= ')';
|
||||||
|
|
||||||
|
return $where_sql;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch visibility SQL for all forums on the board.
|
* Fetch visibility SQL for all forums on the board.
|
||||||
* @param $mode string - either "topic" or "post"
|
* @param $mode string - either "topic" or "post"
|
||||||
|
|
Loading…
Add table
Reference in a new issue