]> git.mxchange.org Git - friendica.git/commitdiff
API: Speed improvements
authorMichael <heluecht@pirati.ca>
Tue, 29 Nov 2022 18:45:30 +0000 (18:45 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 29 Nov 2022 18:45:30 +0000 (18:45 +0000)
database.sql
src/Model/GServer.php
src/Module/Api/Mastodon/Accounts/Statuses.php
static/dbstructure.config.php
static/dbview.config.php
static/routes.config.php

index 04401f4c0d77f2a7279eeb058b4a830450e8623f..596dfa47085f6814acb6d10601c0efb3b9b2bd60 100644 (file)
@@ -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
 --
index 03e42c62b4eacf2a26c53463ba78d8fa31fcdcd2..a128060f4c1694388b8c5f2b83c83856155c8a31 100644 (file)
@@ -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;
index 94811721290c5cbc566f1a32fd3618688abaecc0..b244c56fb258dd71a68d0bceb5b83664aad73a12 100644 (file)
@@ -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);
                }
index 4f231b4c32f12260b9ed5acfe103e728a0706e1a..a72f17032e3dce7ff96ef0446622beefd05c04c6 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1493);
+       define('DB_UPDATE_VERSION', 1494);
 }
 
 return [
index d06904a91f0f91fe96aff09f3061370c7d6fb6aa..a2e3e1b45f395d028e7bf860217b1bf5aac21640 100644 (file)
                        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"],
index da5dda0278dde875d4fd2db295f424446c8c7d00..8d1fec6f0e2c39508e4fc062ae58cd16ebe02f33 100644 (file)
@@ -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