Possible API speed ups for public timeline

This commit is contained in:
Michael 2017-12-17 17:47:15 +00:00
parent a0bf5f8e34
commit 1fbf6c014b

View File

@ -1612,39 +1612,61 @@ function api_statuses_public_timeline($type)
$start = $page * $count; $start = $page * $count;
if ($max_id > 0) { if ($exclude_replies && !$conversation_id) {
$sql_extra = 'AND `item`.`id` <= ' . intval($max_id); if ($max_id > 0) {
} $sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id);
if ($exclude_replies > 0) { }
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
}
$r = q( $r = dba::p("SELECT " . item_fieldlists() . "
"SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, FROM `thread`
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, " . item_joins() . "
`contact`.`id` AS `cid`, STRAIGHT_JOIN `user` ON `user`.`uid` = `thread`.`uid`
`user`.`nickname`, `user`.`hidewall` AND NOT `user`.`hidewall`
FROM `item` AND `verb` = ?
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` AND NOT `thread`.`private`
AND (NOT `contact`.`blocked` OR `contact`.`pending`) AND `thread`.`wall`
STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` AND `thread`.`visible`
AND NOT `user`.`hidewall` AND NOT `thread`.`deleted`
WHERE `verb` = '%s' AND `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND NOT `thread`.`moderated`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `thread`.`iid` > ?
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' $sql_extra
AND NOT `item`.`private` AND `item`.`wall` ORDER BY `thread`.`iid` DESC
$sql_extra LIMIT " . intval($start) . ", " . intval($count),
AND `item`.`id`>%d ACTIVITY_POST,
ORDER BY `item`.`id` DESC LIMIT %d, %d ", $since_id
dbesc(ACTIVITY_POST), );
intval($since_id),
intval($start), $r = dba::inArray($r);
intval($count) } else {
); if ($max_id > 0) {
$sql_extra = 'AND `item`.`id` <= ' . intval($max_id);
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
}
$r = dba::p("SELECT " . item_fieldlists() . "
FROM `item`
" . item_joins() . "
STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
AND NOT `user`.`hidewall`
AND `verb` = ?
AND NOT `item`.`private`
AND `item`.`wall`
AND `item`.`visible`
AND NOT `item`.`deleted`
AND NOT `item`.`moderated`
AND `item`.`id` > ?
$sql_extra
ORDER BY `item`.`id` DESC
LIMIT " . intval($start) . ", " . intval($count),
ACTIVITY_POST,
$since_id
);
$r = dba::inArray($r);
}
$ret = api_format_items($r, $user_info, false, $type); $ret = api_format_items($r, $user_info, false, $type);
@ -1697,11 +1719,15 @@ function api_statuses_networkpublic_timeline($type)
$r = dba::p("SELECT " . item_fieldlists() . " $r = dba::p("SELECT " . item_fieldlists() . "
FROM `thread` FROM `thread`
INNER JOIN `item` ON `item`.`id` = `thread`.`iid` STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
" . item_joins() . " " . item_joins() . "
WHERE `thread`.`uid` = 0 WHERE `thread`.`uid` = 0
AND `verb` = ? AND `verb` = ?
AND `item`.`id` > ? AND NOT `thread`.`private`
AND `thread`.`visible`
AND NOT `thread`.`deleted`
AND NOT `thread`.`moderated`
AND `thread`.`iid` > ?
$sql_extra $sql_extra
ORDER BY `thread`.`iid` DESC ORDER BY `thread`.`iid` DESC
LIMIT " . intval($start) . ", " . intval($count), LIMIT " . intval($start) . ", " . intval($count),