From 176f0c1216f6365a6eb6e7b5698193d494c4119d Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 10 Jun 2022 22:38:46 +0000 Subject: [PATCH] API: Improve the performance for fetching pinned posts --- src/Module/Api/Mastodon/Accounts/Statuses.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Module/Api/Mastodon/Accounts/Statuses.php b/src/Module/Api/Mastodon/Accounts/Statuses.php index 051269797e..95289c6e25 100644 --- a/src/Module/Api/Mastodon/Accounts/Statuses.php +++ b/src/Module/Api/Mastodon/Accounts/Statuses.php @@ -67,15 +67,19 @@ class Statuses extends BaseApi $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], 'uid' => 0, 'network' => Protocol::FEDERATED]; } else { $condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid]; } - $condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))", - GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]); + if (!$request['pinned']) { + $condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))", + GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]); + } if ($request['only_media']) { $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']; } - if ($request['pinned']) { - $condition = DBA::mergeConditions($condition, ['featured' => true]); - } - if ($request['exclude_replies']) { $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 = []; while ($item = Post::fetch($items)) { -- 2.39.5