Merge pull request #12292 from annando/api-speed
API: Speed improvements
This commit is contained in:
commit
ebe512edfd
6 changed files with 50 additions and 9 deletions
20
database.sql
20
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2022.12-dev (Giant Rhubarb)
|
||||
-- DB_UPDATE_VERSION 1493
|
||||
-- DB_UPDATE_VERSION 1494
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -2499,6 +2499,24 @@ CREATE VIEW `collection-view` AS SELECT
|
|||
INNER JOIN `post` ON `post-collection`.`uri-id` = `post`.`uri-id`
|
||||
INNER JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`;
|
||||
|
||||
--
|
||||
-- VIEW media-view
|
||||
--
|
||||
DROP VIEW IF EXISTS `media-view`;
|
||||
CREATE VIEW `media-view` AS SELECT
|
||||
`post-media`.`uri-id` AS `uri-id`,
|
||||
`post-media`.`type` AS `type`,
|
||||
`post`.`received` AS `received`,
|
||||
`post`.`created` AS `created`,
|
||||
`post`.`private` AS `private`,
|
||||
`post`.`visible` AS `visible`,
|
||||
`post`.`deleted` AS `deleted`,
|
||||
`post`.`thr-parent-id` AS `thr-parent-id`,
|
||||
`post`.`author-id` AS `author-id`,
|
||||
`post`.`gravity` AS `gravity`
|
||||
FROM `post-media`
|
||||
INNER JOIN `post` ON `post-media`.`uri-id` = `post`.`uri-id`;
|
||||
|
||||
--
|
||||
-- VIEW tag-view
|
||||
--
|
||||
|
|
|
@ -70,6 +70,7 @@ class GServer
|
|||
const DETECT_UNSPECIFIC = [self::DETECT_MANUAL, self::DETECT_HEADER, self::DETECT_BODY, self::DETECT_HOST_META, self::DETECT_CONTACTS, self::DETECT_AP_ACTOR];
|
||||
|
||||
// Implementation specific endpoints
|
||||
// @todo Possibly add Lemmy detection via the endpoint /api/v3/site
|
||||
const DETECT_FRIENDIKA = 10;
|
||||
const DETECT_FRIENDICA = 11;
|
||||
const DETECT_STATUSNET = 12;
|
||||
|
|
|
@ -69,6 +69,8 @@ class Statuses extends BaseApi
|
|||
|
||||
if ($request['pinned']) {
|
||||
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'type' => Post\Collection::FEATURED];
|
||||
} elseif ($request['only_media']) {
|
||||
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'type' => [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]];
|
||||
} elseif (!$uid) {
|
||||
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
|
||||
'uid' => 0, 'network' => Protocol::FEDERATED];
|
||||
|
@ -76,16 +78,11 @@ class Statuses extends BaseApi
|
|||
$condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid];
|
||||
}
|
||||
|
||||
if (!$request['pinned']) {
|
||||
if (!$request['pinned'] && !$request['only_media']) {
|
||||
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
||||
Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Item::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 (?, ?, ?))",
|
||||
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
|
||||
}
|
||||
|
||||
if (!empty($request['max_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
|
||||
}
|
||||
|
@ -99,12 +96,16 @@ class Statuses extends BaseApi
|
|||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
if ($request['exclude_replies']) {
|
||||
if (($request['pinned'] || $request['only_media']) && $request['exclude_replies']) {
|
||||
$condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
|
||||
}
|
||||
|
||||
if ($request['pinned']) {
|
||||
$items = DBA::select('collection-view', ['uri-id'], $condition, $params);
|
||||
} elseif ($request['only_media']) {
|
||||
$items = DBA::select('media-view', ['uri-id'], $condition, $params);
|
||||
} elseif ($request['exclude_replies']) {
|
||||
$items = Post::selectThreadForUser($uid, ['uri-id'], $condition, $params);
|
||||
} else {
|
||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1493);
|
||||
define('DB_UPDATE_VERSION', 1494);
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
|
@ -723,6 +723,22 @@
|
|||
INNER JOIN `post` ON `post-collection`.`uri-id` = `post`.`uri-id`
|
||||
INNER JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`"
|
||||
],
|
||||
"media-view" => [
|
||||
"fields" => [
|
||||
"uri-id" => ["post-media", "uri-id"],
|
||||
"type" => ["post-media", "type"],
|
||||
"received" => ["post", "received"],
|
||||
"created" => ["post", "created"],
|
||||
"private" => ["post", "private"],
|
||||
"visible" => ["post", "visible"],
|
||||
"deleted" => ["post", "deleted"],
|
||||
"thr-parent-id" => ["post", "thr-parent-id"],
|
||||
"author-id" => ["post", "author-id"],
|
||||
"gravity" => ["post", "gravity"],
|
||||
],
|
||||
"query" => "FROM `post-media`
|
||||
INNER JOIN `post` ON `post-media`.`uri-id` = `post`.`uri-id`"
|
||||
],
|
||||
"tag-view" => [
|
||||
"fields" => [
|
||||
"uri-id" => ["post-tag", "uri-id"],
|
||||
|
|
|
@ -239,6 +239,8 @@ return [
|
|||
'/followed_tags' => [Module\Api\Mastodon\FollowedTags::class, [R::GET ]],
|
||||
'/instance' => [Module\Api\Mastodon\Instance::class, [R::GET ]],
|
||||
'/instance/activity' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/instance/domain_blocks' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/instance/extended_description' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // @todo
|
||||
'/instance/peers' => [Module\Api\Mastodon\Instance\Peers::class, [R::GET ]],
|
||||
'/instance/rules' => [Module\Api\Mastodon\Instance\Rules::class, [R::GET ]],
|
||||
'/lists' => [Module\Api\Mastodon\Lists::class, [R::GET, R::POST]],
|
||||
|
@ -300,6 +302,9 @@ return [
|
|||
'/trends/statuses' => [Module\Api\Mastodon\Trends\Statuses::class, [R::GET ]],
|
||||
'/trends/tags' => [Module\Api\Mastodon\Trends\Tags::class, [R::GET ]],
|
||||
],
|
||||
'/v2' => [
|
||||
'/instance' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not supported
|
||||
],
|
||||
'/v{version:\d+}' => [
|
||||
'/admin/accounts' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not supported
|
||||
'/filters' => [Module\Api\Mastodon\Filters::class, [R::GET ]], // Dummy, not supported
|
||||
|
|
Loading…
Reference in a new issue