API: Improve the performance for fetching pinned posts
This commit is contained in:
parent
143120b9c4
commit
176f0c1216
1 changed files with 12 additions and 8 deletions
|
@ -67,15 +67,19 @@ class Statuses extends BaseApi
|
||||||
|
|
||||||
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
|
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
|
||||||
|
|
||||||
if (!$uid) {
|
if ($request['pinned']) {
|
||||||
|
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]];
|
||||||
|
} elseif (!$uid) {
|
||||||
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
|
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
|
||||||
'uid' => 0, 'network' => Protocol::FEDERATED];
|
'uid' => 0, 'network' => Protocol::FEDERATED];
|
||||||
} else {
|
} else {
|
||||||
$condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid];
|
$condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid];
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
if (!$request['pinned']) {
|
||||||
GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
||||||
|
GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($request['only_media']) {
|
if ($request['only_media']) {
|
||||||
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
|
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
|
||||||
|
@ -95,15 +99,15 @@ class Statuses extends BaseApi
|
||||||
$params['order'] = ['uri-id'];
|
$params['order'] = ['uri-id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request['pinned']) {
|
|
||||||
$condition = DBA::mergeConditions($condition, ['featured' => true]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request['exclude_replies']) {
|
if ($request['exclude_replies']) {
|
||||||
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
|
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
if ($request['pinned']) {
|
||||||
|
$items = DBA::select('collection-view', ['uri-id'], $condition, $params);
|
||||||
|
} else {
|
||||||
|
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||||
|
}
|
||||||
|
|
||||||
$statuses = [];
|
$statuses = [];
|
||||||
while ($item = Post::fetch($items)) {
|
while ($item = Post::fetch($items)) {
|
||||||
|
|
Loading…
Reference in a new issue