Merge pull request #5315 from annando/item-improved
Only use query conditions in user mode
This commit is contained in:
commit
8cae2583b6
|
@ -279,7 +279,7 @@ class Item extends BaseObject
|
||||||
|
|
||||||
$param_string = self::addTablesToFields(dba::buildParameter($params), $fields);
|
$param_string = self::addTablesToFields(dba::buildParameter($params), $fields);
|
||||||
|
|
||||||
$table = "`item` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, false);
|
$table = "`item` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, false, $usermode);
|
||||||
|
|
||||||
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
|
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ class Item extends BaseObject
|
||||||
$param_string = self::addTablesToFields($param_string, $threadfields);
|
$param_string = self::addTablesToFields($param_string, $threadfields);
|
||||||
$param_string = self::addTablesToFields($param_string, $fields);
|
$param_string = self::addTablesToFields($param_string, $fields);
|
||||||
|
|
||||||
$table = "`thread` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, true);
|
$table = "`thread` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, true, $usermode);
|
||||||
|
|
||||||
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
|
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ class Item extends BaseObject
|
||||||
*
|
*
|
||||||
* @return string The SQL joins for the "select" functions
|
* @return string The SQL joins for the "select" functions
|
||||||
*/
|
*/
|
||||||
private static function constructJoins($uid, $sql_commands, $thread_mode)
|
private static function constructJoins($uid, $sql_commands, $thread_mode, $user_mode)
|
||||||
{
|
{
|
||||||
if ($thread_mode) {
|
if ($thread_mode) {
|
||||||
$master_table = "`thread`";
|
$master_table = "`thread`";
|
||||||
|
@ -485,6 +485,7 @@ class Item extends BaseObject
|
||||||
$joins = '';
|
$joins = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($user_mode) {
|
||||||
$joins .= sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`
|
$joins .= sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`
|
||||||
AND NOT `contact`.`blocked`
|
AND NOT `contact`.`blocked`
|
||||||
AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
|
AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
|
||||||
|
@ -493,6 +494,17 @@ class Item extends BaseObject
|
||||||
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked`
|
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked`
|
||||||
LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d",
|
LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d",
|
||||||
CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid));
|
CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid));
|
||||||
|
} else {
|
||||||
|
if (strpos($sql_commands, "`contact`.") !== false) {
|
||||||
|
$joins .= "STRAIGHT_JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`";
|
||||||
|
}
|
||||||
|
if (strpos($sql_commands, "`author`.") !== false) {
|
||||||
|
$joins .= " STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id`";
|
||||||
|
}
|
||||||
|
if (strpos($sql_commands, "`owner`.") !== false) {
|
||||||
|
$joins .= " STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id`";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (strpos($sql_commands, "`group_member`.") !== false) {
|
if (strpos($sql_commands, "`group_member`.") !== false) {
|
||||||
$joins .= " STRAIGHT_JOIN `group_member` ON `group_member`.`contact-id` = $master_table.`contact-id`";
|
$joins .= " STRAIGHT_JOIN `group_member` ON `group_member`.`contact-id` = $master_table.`contact-id`";
|
||||||
|
|
Loading…
Reference in a new issue