]> git.mxchange.org Git - friendica.git/commitdiff
API: Speed improvements when fetching posts
authorMichael <heluecht@pirati.ca>
Fri, 10 Jun 2022 18:49:03 +0000 (18:49 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 10 Jun 2022 18:49:03 +0000 (18:49 +0000)
database.sql
src/App.php
src/App/Page.php
src/Core/System.php
src/Factory/Api/Mastodon/Account.php
src/Factory/Api/Mastodon/Status.php
src/Object/Api/Mastodon/Account.php
static/dbstructure.config.php
static/dbview.config.php

index ce9d74cc680bcb4362bb5922fac07dafbf65929a..b24f2ed5f66432630734156d02d06915a819e7f0 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.05-rc (Siberian Iris)
--- DB_UPDATE_VERSION 1468
+-- DB_UPDATE_VERSION 1469
 -- ------------------------------------------
 
 
@@ -1752,6 +1752,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `post-content`.`target` AS `target`,
        `post-content`.`resource-id` AS `resource-id`,
        `post-user`.`contact-id` AS `contact-id`,
+       `contact`.`uri-id` AS `contact-uri-id`,
        `contact`.`url` AS `contact-link`,
        `contact`.`addr` AS `contact-addr`,
        `contact`.`name` AS `contact-name`,
@@ -1776,6 +1777,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `contact`.`avatar-date` AS `avatar-date`,
        `contact`.`thumb` AS `thumb`,
        `post-user`.`author-id` AS `author-id`,
+       `author`.`uri-id` AS `author-uri-id`,
        `author`.`url` AS `author-link`,
        `author`.`addr` AS `author-addr`,
        IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
@@ -1786,8 +1788,8 @@ CREATE VIEW `post-user-view` AS SELECT
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
        `author`.`gsid` AS `author-gsid`,
-       `author`.`uri-id` AS `author-uri-id`,
        `post-user`.`owner-id` AS `owner-id`,
+       `owner`.`uri-id` AS `owner-uri-id`,
        `owner`.`url` AS `owner-link`,
        `owner`.`addr` AS `owner-addr`,
        IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
@@ -1799,6 +1801,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `owner`.`updated` AS `owner-updated`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post-user`.`causer-id` AS `causer-id`,
+       `causer`.`uri-id` AS `causer-uri-id`,
        `causer`.`url` AS `causer-link`,
        `causer`.`addr` AS `causer-addr`,
        `causer`.`name` AS `causer-name`,
@@ -1923,6 +1926,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `post-content`.`target` AS `target`,
        `post-content`.`resource-id` AS `resource-id`,
        `post-thread-user`.`contact-id` AS `contact-id`,
+       `contact`.`uri-id` AS `contact-uri-id`,
        `contact`.`url` AS `contact-link`,
        `contact`.`addr` AS `contact-addr`,
        `contact`.`name` AS `contact-name`,
@@ -1947,6 +1951,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `contact`.`avatar-date` AS `avatar-date`,
        `contact`.`thumb` AS `thumb`,
        `post-thread-user`.`author-id` AS `author-id`,
+       `author`.`uri-id` AS `author-uri-id`,
        `author`.`url` AS `author-link`,
        `author`.`addr` AS `author-addr`,
        IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
@@ -1957,8 +1962,8 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
        `author`.`gsid` AS `author-gsid`,
-       `author`.`uri-id` AS `author-uri-id`,
        `post-thread-user`.`owner-id` AS `owner-id`,
+       `owner`.`uri-id` AS `owner-uri-id`,
        `owner`.`url` AS `owner-link`,
        `owner`.`addr` AS `owner-addr`,
        IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
@@ -1970,6 +1975,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `owner`.`updated` AS `owner-updated`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post-thread-user`.`causer-id` AS `causer-id`,
+       `causer`.`uri-id` AS `causer-uri-id`,
        `causer`.`url` AS `causer-link`,
        `causer`.`addr` AS `causer-addr`,
        `causer`.`name` AS `causer-name`,
@@ -2080,6 +2086,7 @@ CREATE VIEW `post-view` AS SELECT
        `post-content`.`target` AS `target`,
        `post-content`.`resource-id` AS `resource-id`,
        `post`.`author-id` AS `contact-id`,
+       `author`.`uri-id` AS `contact-uri-id`,
        `author`.`url` AS `contact-link`,
        `author`.`addr` AS `contact-addr`,
        `author`.`name` AS `contact-name`,
@@ -2104,6 +2111,7 @@ CREATE VIEW `post-view` AS SELECT
        `author`.`avatar-date` AS `avatar-date`,
        `author`.`thumb` AS `thumb`,
        `post`.`author-id` AS `author-id`,
+       `author`.`uri-id` AS `author-uri-id`,
        `author`.`url` AS `author-link`,
        `author`.`addr` AS `author-addr`,
        `author`.`name` AS `author-name`,
@@ -2114,8 +2122,8 @@ CREATE VIEW `post-view` AS SELECT
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
        `author`.`gsid` AS `author-gsid`,
-       `author`.`uri-id` AS `author-uri-id`,
        `post`.`owner-id` AS `owner-id`,
+       `owner`.`uri-id` AS `owner-uri-id`,
        `owner`.`url` AS `owner-link`,
        `owner`.`addr` AS `owner-addr`,
        `owner`.`name` AS `owner-name`,
@@ -2127,6 +2135,7 @@ CREATE VIEW `post-view` AS SELECT
        `owner`.`updated` AS `owner-updated`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post`.`causer-id` AS `causer-id`,
+       `causer`.`uri-id` AS `causer-uri-id`,
        `causer`.`url` AS `causer-link`,
        `causer`.`addr` AS `causer-addr`,
        `causer`.`name` AS `causer-name`,
@@ -2213,6 +2222,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `post-content`.`target` AS `target`,
        `post-content`.`resource-id` AS `resource-id`,
        `post-thread`.`author-id` AS `contact-id`,
+       `author`.`uri-id` AS `contact-uri-id`,
        `author`.`url` AS `contact-link`,
        `author`.`addr` AS `contact-addr`,
        `author`.`name` AS `contact-name`,
@@ -2237,6 +2247,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `author`.`avatar-date` AS `avatar-date`,
        `author`.`thumb` AS `thumb`,
        `post-thread`.`author-id` AS `author-id`,
+       `author`.`uri-id` AS `author-uri-id`,
        `author`.`url` AS `author-link`,
        `author`.`addr` AS `author-addr`,
        `author`.`name` AS `author-name`,
@@ -2247,8 +2258,8 @@ CREATE VIEW `post-thread-view` AS SELECT
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
        `author`.`gsid` AS `author-gsid`,
-       `author`.`uri-id` AS `author-uri-id`,
        `post-thread`.`owner-id` AS `owner-id`,
+       `owner`.`uri-id` AS `owner-uri-id`,
        `owner`.`url` AS `owner-link`,
        `owner`.`addr` AS `owner-addr`,
        `owner`.`name` AS `owner-name`,
@@ -2260,6 +2271,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `owner`.`updated` AS `owner-updated`,
        `owner`.`contact-type` AS `owner-contact-type`,
        `post-thread`.`causer-id` AS `causer-id`,
+       `causer`.`uri-id` AS `causer-uri-id`,
        `causer`.`url` AS `causer-link`,
        `causer`.`addr` AS `causer-addr`,
        `causer`.`name` AS `causer-name`,
@@ -2705,6 +2717,9 @@ CREATE VIEW `account-user-view` AS SELECT
        `fcontact`.`notify` AS `diaspora-notify`,
        `fcontact`.`poll` AS `diaspora-poll`,
        `fcontact`.`alias` AS `diaspora-alias`,
+       `fcontact`.`interacting_count` AS `diaspora-interacting_count`,
+       `fcontact`.`interacted_count` AS `diaspora-interacted_count`,
+       `fcontact`.`post_count` AS `diaspora-post_count`,
        `apcontact`.`uuid` AS `ap-uuid`,
        `apcontact`.`type` AS `ap-type`,
        `apcontact`.`following` AS `ap-following`,
index e55938d39c797604326509d16006daedec274168..6fa79c50144190638e8de86c1a1542dc5be8c0bb 100644 (file)
@@ -719,7 +719,7 @@ class App
                } catch (HTTPException $e) {
                        (new ModuleHTTPException())->rawContent($e);
                }
-               $page->logRuntime($this->config);
+               $page->logRuntime($this->config, 'runFrontend');
        }
 
        /**
index c78d0f9e0c53b5f95a4a34774b62bfdfcf9f52a0..d38757687c99929bd62b8055fa7d78be1ac6a317 100644 (file)
@@ -98,7 +98,7 @@ class Page implements ArrayAccess
                $this->method  = $method;
        }
 
-       public function logRuntime(IManageConfigValues $config)
+       public function logRuntime(IManageConfigValues $config, string $origin = '')
        {
                if (in_array($this->command, $config->get('system', 'runtime_ignore'))) {
                        return;
@@ -106,7 +106,7 @@ class Page implements ArrayAccess
 
                $runtime = number_format(microtime(true) - $this->timestamp, 3);
                if ($runtime > $config->get('system', 'runtime_loglimit')) {
-                       Logger::debug('Runtime', ['method' => $this->method, 'command' => $this->command, 'runtime' => $runtime]);
+                       Logger::debug('Runtime', ['method' => $this->method, 'command' => $this->command, 'runtime' => $runtime, 'origin' => $origin]);
                }
        }
 
index 6f1bb618842a07e52c9c2ecf178a3d31338a5628..7601a6f840480caed0bcb597c08600852bc0eb8a 100644 (file)
@@ -369,7 +369,7 @@ class System
         */
        public static function exit()
        {
-               DI::page()->logRuntime(DI::config());
+               DI::page()->logRuntime(DI::config(), 'exit');
                exit();
        }
 
index cf836275c15d227fde72bc6faba391595dedcf8a..42351969aff414ebad020941c69bd5863450bfa0 100644 (file)
@@ -24,9 +24,8 @@ namespace Friendica\Factory\Api\Mastodon;
 use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
 use Friendica\Collection\Api\Mastodon\Fields;
-use Friendica\Model\APContact;
+use Friendica\Database\DBA;
 use Friendica\Model\Contact;
-use Friendica\Model\FContact;
 use Friendica\Network\HTTPException;
 use Friendica\Profile\ProfileField\Repository\ProfileField as ProfileFieldRepository;
 use ImagickException;
@@ -60,31 +59,39 @@ class Account extends BaseFactory
         */
        public function createFromContactId(int $contactId, $uid = 0): \Friendica\Object\Api\Mastodon\Account
        {
-               $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
-               if (!empty($cdata)) {
-                       $publicContact = Contact::getById($cdata['public']);
-                       $userContact   = Contact::getById($cdata['user']);
-               } else {
-                       $publicContact = Contact::getById($contactId);
-                       $userContact   = [];
+               $contact = Contact::getById($contactId, ['uri-id']);
+               if (empty($contact)) {
+                       throw new HTTPException\NotFoundException('Contact ' . $contactId . ' not found');
                }
+               return self::createFromUriId($contact['uri-id'], $uid);
+       }
 
-               if (empty($publicContact)) {
-                       throw new HTTPException\NotFoundException('Contact ' . $contactId . ' not found');
+       /**
+        * @param int $contactUriId
+        * @param int $uid          Public contact (=0) or owner user id
+        *
+        * @return \Friendica\Object\Api\Mastodon\Account
+        * @throws HTTPException\InternalServerErrorException
+        * @throws ImagickException|HTTPException\NotFoundException
+        */
+       public function createFromUriId(int $contactUriId, $uid = 0): \Friendica\Object\Api\Mastodon\Account
+       {
+               $contact = DBA::selectFirst('account-user-view', [], ['uri-id' => $contactUriId, 'uid' => [0, $uid]], ['order' => ['id' => true]]);
+               if (empty($contact)) {
+                       throw new HTTPException\NotFoundException('Contact ' . $contactUriId . ' not found');
                }
 
-               $apcontact = APContact::getByURL($publicContact['url'], false);
-               $fcontact  = FContact::getByURL($publicContact['url'], false);
+               $fields = new Fields();
 
-               $self_contact = Contact::selectFirst(['uid'], ['nurl' => $publicContact['nurl'], 'self' => true]);
-               if (!empty($self_contact['uid'])) {
-                       $profileFields = $this->profileFieldRepo->selectPublicFieldsByUserId($self_contact['uid']);
-                       $fields        = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
-               } else {
-                       $fields = new Fields();
+               if (Contact::isLocal($contact['url'])) {
+                       $self_contact = Contact::selectFirst(['uid'], ['nurl' => $contact['nurl'], 'self' => true]);
+                       if (!empty($self_contact['uid'])) {
+                               $profileFields = $this->profileFieldRepo->selectPublicFieldsByUserId($self_contact['uid']);
+                               $fields        = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
+                       }
                }
 
-               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact, $userContact, $fcontact);
+               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $contact, $fields);
        }
 
        /**
@@ -94,13 +101,10 @@ class Account extends BaseFactory
         */
        public function createFromUserId(int $userId): \Friendica\Object\Api\Mastodon\Account
        {
-               $publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
-
+               $contact       = DBA::selectFirst('account-user-view', [], ['uid' => $userId, 'self' => true]);
                $profileFields = $this->profileFieldRepo->selectPublicFieldsByUserId($userId);
                $fields        = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
 
-               $apContact = APContact::getByURL($publicContact['url'], false);
-
-               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apContact);
+               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $contact, $fields);
        }
 }
index cac9dfd06aa9513c405407b9cbfb34270a530a12..63dc7c4e7c287ccb01328c7ac2571e8bb08b47d8 100644 (file)
@@ -78,10 +78,10 @@ class Status extends BaseFactory
         * @throws HTTPException\InternalServerErrorException
         * @throws ImagickException|HTTPException\NotFoundException
         */
-       public function createFromUriId(int $uriId, $uid = 0): \Friendica\Object\Api\Mastodon\Status
+       public function createFromUriId(int $uriId, $uid = 0, $item = []): \Friendica\Object\Api\Mastodon\Status
        {
-               $fields = ['uri-id', 'uid', 'author-id', 'author-link', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
-                       'created', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured'];
+               $fields = ['uri-id', 'uid', 'author-id', 'author-uri-id', 'author-link', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
+                       'created', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured', 'has-media'];
                $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
                if (!$item) {
                        $mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]);
@@ -90,42 +90,46 @@ class Status extends BaseFactory
                        }
                        throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
                }
-
-               $account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);
+               $account = $this->mstdnAccountFactory->createFromUriId($item['author-uri-id'], $uid);
+
+               $count_announce = Post::countPosts([
+                       'thr-parent-id' => $uriId,
+                       'gravity'       => GRAVITY_ACTIVITY,
+                       'vid'           => Verb::getID(Activity::ANNOUNCE),
+                       'deleted'       => false
+               ], []);
+               $count_like = Post::countPosts([
+                       'thr-parent-id' => $uriId,
+                       'gravity'       => GRAVITY_ACTIVITY,
+                       'vid'           => Verb::getID(Activity::LIKE),
+                       'deleted'       => false
+               ], []);
 
                $counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
                        Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], []),
-                       Post::countPosts([
-                               'thr-parent-id' => $uriId,
-                               'gravity'       => GRAVITY_ACTIVITY,
-                               'vid'           => Verb::getID(Activity::ANNOUNCE),
-                               'deleted'       => false
-                       ], []),
-                       Post::countPosts([
-                               'thr-parent-id' => $uriId,
-                               'gravity'       => GRAVITY_ACTIVITY,
-                               'vid'           => Verb::getID(Activity::LIKE),
-                               'deleted'       => false
-                       ], [])
+                       $count_announce,
+                       $count_like
                );
 
+               $origin_like = ($count_like == 0) ? false : Post::exists([
+                       'thr-parent-id' => $uriId,
+                       'uid'           => $uid,
+                       'origin'        => true,
+                       'gravity'       => GRAVITY_ACTIVITY,
+                       'vid'           => Verb::getID(Activity::LIKE),
+                       'deleted'     => false
+               ]);
+               $origin_announce = ($count_announce == 0) ? false : Post::exists([
+                       'thr-parent-id' => $uriId,
+                       'uid'           => $uid,
+                       'origin'        => true,
+                       'gravity'       => GRAVITY_ACTIVITY,
+                       'vid'           => Verb::getID(Activity::ANNOUNCE),
+                       'deleted'       => false
+               ]);
                $userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
-                       Post::exists([
-                               'thr-parent-id' => $uriId,
-                               'uid'           => $uid,
-                               'origin'        => true,
-                               'gravity'       => GRAVITY_ACTIVITY,
-                               'vid'           => Verb::getID(Activity::LIKE)
-                               , 'deleted'     => false
-                       ]),
-                       Post::exists([
-                               'thr-parent-id' => $uriId,
-                               'uid'           => $uid,
-                               'origin'        => true,
-                               'gravity'       => GRAVITY_ACTIVITY,
-                               'vid'           => Verb::getID(Activity::ANNOUNCE),
-                               'deleted'       => false
-                       ]),
+                       $origin_like,
+                       $origin_announce,
                        Post\ThreadUser::getIgnored($uriId, $uid),
                        (bool)($item['starred'] && ($item['gravity'] == GRAVITY_PARENT)),
                        $item['featured']
@@ -136,8 +140,13 @@ class Status extends BaseFactory
 
                $mentions    = $this->mstdnMentionFactory->createFromUriId($uriId)->getArrayCopy();
                $tags        = $this->mstdnTagFactory->createFromUriId($uriId);
-               $card        = $this->mstdnCardFactory->createFromUriId($uriId);
-               $attachments = $this->mstdnAttachementFactory->createFromUriId($uriId);
+               if ($item['has-media']) {
+                       $card        = $this->mstdnCardFactory->createFromUriId($uriId);
+                       $attachments = $this->mstdnAttachementFactory->createFromUriId($uriId);
+               } else {
+                       $card        = new \Friendica\Object\Api\Mastodon\Card([]);
+                       $attachments = [];
+               }
 
                if (!empty($item['question-id'])) {
                        $poll = $this->mstdnPollFactory->createFromId($item['question-id'], $uid)->toArray();
@@ -160,7 +169,6 @@ class Status extends BaseFactory
                        }
                }
 
-
                if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
                        $reshare       = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
                        $reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $uid]]);
index 3dbe6b7fdad03e2aaf43a2d10ddf69f0d0c21e33..aac23ef5ed3d24163a10c49d41ae3a0f3cca7c1f 100644 (file)
@@ -86,52 +86,42 @@ class Account extends BaseDataTransferObject
         * Creates an account record from a public contact record. Expects all contact table fields to be set.
         *
         * @param BaseURL $baseUrl
-        * @param array   $publicContact Full contact table record with uid = 0
-        * @param array   $apcontact     Optional full apcontact table record
-        * @param array   $userContact   Optional full contact table record with uid != 0
-        * @param array   $fcontact      Optional full fcontact table record
+        * @param array   $contact entry of "account-user-view"
+        * @param Fields  $fields  Profile fields
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function __construct(BaseURL $baseUrl, array $publicContact, Fields $fields, array $apcontact = [], array $userContact = [], array $fcontact = [])
+       public function __construct(BaseURL $baseUrl, array $contact, Fields $fields)
        {
-               $this->id              = (string)$publicContact['id'];
-               $this->username        = $publicContact['nick'];
+               $this->id              = (string)$contact['pid'];
+               $this->username        = $contact['nick'];
                $this->acct            =
-                       strpos($publicContact['url'], $baseUrl->get() . '/') === 0 ?
-                               $publicContact['nick'] :
-                               $publicContact['addr'];
-               $this->display_name    = $publicContact['name'];
-               $this->locked          = (bool)$publicContact['manually-approve'] ?? !empty($apcontact['manually-approve']);
-               $this->bot             = ($publicContact['contact-type'] == Contact::TYPE_NEWS);
-               $this->discoverable    = !$publicContact['unsearchable'];
-               $this->group           = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY);
+                       strpos($contact['url'], $baseUrl->get() . '/') === 0 ?
+                               $contact['nick'] :
+                               $contact['addr'];
+               $this->display_name    = $contact['name'];
+               $this->locked          = (bool)$contact['manually-approve'];
+               $this->bot             = ($contact['contact-type'] == Contact::TYPE_NEWS);
+               $this->discoverable    = !$contact['unsearchable'];
+               $this->group           = ($contact['contact-type'] == Contact::TYPE_COMMUNITY);
 
-               $publicContactCreated = $publicContact['created'] ?: DBA::NULL_DATETIME;
-               $userContactCreated = $userContact['created'] ?? DBA::NULL_DATETIME;
+               $this->created_at      = DateTimeFormat::utc($contact['created'] ?: DBA::NULL_DATETIME, DateTimeFormat::JSON);
 
-               $created = $userContactCreated < $publicContactCreated && ($userContactCreated != DBA::NULL_DATETIME) ? $userContactCreated : $publicContactCreated;
-               $this->created_at      = DateTimeFormat::utc($created, DateTimeFormat::JSON);
-
-               $this->note            = BBCode::convertForUriId($publicContact['uri-id'] ?? 0, $publicContact['about'], BBCode::EXTERNAL);
-               $this->url             = $publicContact['url'];
-               $this->avatar          = Contact::getAvatarUrlForId($userContact['id'] ?? 0 ?: $publicContact['id'], Proxy::SIZE_SMALL, $userContact['updated'] ?? '' ?: $publicContact['updated']);
+               $this->note            = BBCode::convertForUriId($contact['uri-id'], $contact['about'], BBCode::EXTERNAL);
+               $this->url             = $contact['url'];
+               $this->avatar          = Contact::getAvatarUrlForId($contact['id'] ?? 0 ?: $contact['pid'], Proxy::SIZE_SMALL, $contact['updated'], $contact['guid'] ?? '');
                $this->avatar_static   = $this->avatar;
-               $this->header          = Contact::getHeaderUrlForId($userContact['id'] ?? 0 ?: $publicContact['id'], '', $userContact['updated'] ?? '' ?: $publicContact['updated']);
+               $this->header          = Contact::getHeaderUrlForId($contact['id'] ?? 0 ?: $contact['pid'], '', $contact['updated'], $contact['guid'] ?? '');
                $this->header_static   = $this->header;
-               $this->followers_count = $apcontact['followers_count'] ?? $fcontact['interacted_count'] ?? 0;
-               $this->following_count = $apcontact['following_count'] ?? $fcontact['interacting_count'] ?? 0;
-               $this->statuses_count  = $apcontact['statuses_count'] ?? $fcontact['post_count'] ?? 0;
-
-               $publicContactLastItem = $publicContact['last-item'] ?: DBA::NULL_DATETIME;
-               $userContactLastItem = $userContact['last-item'] ?? DBA::NULL_DATETIME;
+               $this->followers_count = $contact['ap-followers_count'] ?? $contact['diaspora-interacted_count'] ?? 0;
+               $this->following_count = $contact['ap-following_count'] ?? $contact['diaspora-interacting_count'] ?? 0;
+               $this->statuses_count  = $contact['ap-statuses_count'] ?? $contact['diaspora-post_count'] ?? 0;
 
-               $lastItem = $userContactLastItem > $publicContactLastItem ? $userContactLastItem : $publicContactLastItem;
+               $lastItem = $contact['last-item'] ?: DBA::NULL_DATETIME;
                $this->last_status_at  = $lastItem != DBA::NULL_DATETIME ? DateTimeFormat::utc($lastItem, 'Y-m-d') : null;
 
                // No custom emojis per account in Friendica
                $this->emojis          = [];
                $this->fields          = $fields->getArrayCopy();
-
        }
 
        /**
index 011a298a57f90814b1a917ec2c91f91ac08f670e..d365f98050b0e4785698da66618cae00fe11a2e5 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1468);
+       define('DB_UPDATE_VERSION', 1469);
 }
 
 return [
index 68217118ccaa34e310e6ebfa52c7c70f12655938..040a9ebc306e19500e730ff3131b38998acaaf71 100644 (file)
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
                        "contact-id" => ["post-user", "contact-id"],
+                       "contact-uri-id" => ["contact", "uri-id"],
                        "contact-link" => ["contact", "url"],
                        "contact-addr" => ["contact", "addr"],
                        "contact-name" => ["contact", "name"],
                        "avatar-date" => ["contact", "avatar-date"],
                        "thumb" => ["contact", "thumb"],
                        "author-id" => ["post-user", "author-id"],
+                       "author-uri-id" => ["author", "uri-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "author-name" => "IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`)",
                        "author-gsid" => ["author", "gsid"],
                        "author-uri-id" => ["author", "uri-id"],
                        "owner-id" => ["post-user", "owner-id"],
+                       "owner-uri-id" => ["owner", "uri-id"],
                        "owner-link" => ["owner", "url"],
                        "owner-addr" => ["owner", "addr"],
                        "owner-name" => "IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`)",
                        "owner-updated" => ["owner", "updated"],
                        "owner-contact-type" => ["owner", "contact-type"],
                        "causer-id" => ["post-user", "causer-id"],
+                       "causer-uri-id" => ["causer", "uri-id"],
                        "causer-link" => ["causer", "url"],
                        "causer-addr" => ["causer", "addr"],
                        "causer-name" => ["causer", "name"],
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
                        "contact-id" => ["post-thread-user", "contact-id"],
+                       "contact-uri-id" => ["contact", "uri-id"],
                        "contact-link" => ["contact", "url"],
                        "contact-addr" => ["contact", "addr"],
                        "contact-name" => ["contact", "name"],
                        "avatar-date" => ["contact", "avatar-date"],
                        "thumb" => ["contact", "thumb"],
                        "author-id" => ["post-thread-user", "author-id"],
+                       "author-uri-id" => ["author", "uri-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "author-name" => "IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`)",
                        "author-gsid" => ["author", "gsid"],
                        "author-uri-id" => ["author", "uri-id"],
                        "owner-id" => ["post-thread-user", "owner-id"],
+                       "owner-uri-id" => ["owner", "uri-id"],
                        "owner-link" => ["owner", "url"],
                        "owner-addr" => ["owner", "addr"],
                        "owner-name" => "IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`)",
                        "owner-updated" => ["owner", "updated"],
                        "owner-contact-type" => ["owner", "contact-type"],
                        "causer-id" => ["post-thread-user", "causer-id"],
+                       "causer-uri-id" => ["causer", "uri-id"],
                        "causer-link" => ["causer", "url"],
                        "causer-addr" => ["causer", "addr"],
                        "causer-name" => ["causer", "name"],
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
                        "contact-id" => ["post", "author-id"],
+                       "contact-uri-id" => ["author", "uri-id"],
                        "contact-link" => ["author", "url"],
                        "contact-addr" => ["author", "addr"],
                        "contact-name" => ["author", "name"],
                        "avatar-date" => ["author", "avatar-date"],
                        "thumb" => ["author", "thumb"],
                        "author-id" => ["post", "author-id"],
+                       "author-uri-id" => ["author", "uri-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "author-name" => ["author", "name"],
                        "author-gsid" => ["author", "gsid"],
                        "author-uri-id" => ["author", "uri-id"],
                        "owner-id" => ["post", "owner-id"],
+                       "owner-uri-id" => ["owner", "uri-id"],
                        "owner-link" => ["owner", "url"],
                        "owner-addr" => ["owner", "addr"],
                        "owner-name" => ["owner", "name"],
                        "owner-updated" => ["owner", "updated"],
                        "owner-contact-type" => ["owner", "contact-type"],
                        "causer-id" => ["post", "causer-id"],
+                       "causer-uri-id" => ["causer", "uri-id"],
                        "causer-link" => ["causer", "url"],
                        "causer-addr" => ["causer", "addr"],
                        "causer-name" => ["causer", "name"],
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
                        "contact-id" => ["post-thread", "author-id"],
+                       "contact-uri-id" => ["author", "uri-id"],
                        "contact-link" => ["author", "url"],
                        "contact-addr" => ["author", "addr"],
                        "contact-name" => ["author", "name"],
                        "avatar-date" => ["author", "avatar-date"],
                        "thumb" => ["author", "thumb"],
                        "author-id" => ["post-thread", "author-id"],
+                       "author-uri-id" => ["author", "uri-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "author-name" => ["author", "name"],
                        "author-gsid" => ["author", "gsid"],
                        "author-uri-id" => ["author", "uri-id"],
                        "owner-id" => ["post-thread", "owner-id"],
+                       "owner-uri-id" => ["owner", "uri-id"],
                        "owner-link" => ["owner", "url"],
                        "owner-addr" => ["owner", "addr"],
                        "owner-name" => ["owner", "name"],
                        "owner-updated" => ["owner", "updated"],
                        "owner-contact-type" => ["owner", "contact-type"],
                        "causer-id" => ["post-thread", "causer-id"],
+                       "causer-uri-id" => ["causer", "uri-id"],
                        "causer-link" => ["causer", "url"],
                        "causer-addr" => ["causer", "addr"],
                        "causer-name" => ["causer", "name"],
                        "diaspora-notify" => ["fcontact", "notify"],
                        "diaspora-poll" => ["fcontact", "poll"],
                        "diaspora-alias" => ["fcontact", "alias"],
+                       "diaspora-interacting_count" => ["fcontact", "interacting_count"],
+                       "diaspora-interacted_count" => ["fcontact", "interacted_count"],
+                       "diaspora-post_count" => ["fcontact", "post_count"],
                        "ap-uuid" => ["apcontact", "uuid"],
                        "ap-type" => ["apcontact", "type"],
                        "ap-following" => ["apcontact", "following"],