]> git.mxchange.org Git - friendica.git/commitdiff
Avoid unneeded database calls when showing posts of contacts
authorMichael <heluecht@pirati.ca>
Tue, 9 Jun 2020 22:38:06 +0000 (22:38 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 9 Jun 2020 22:38:06 +0000 (22:38 +0000)
src/Model/Contact.php
src/Module/Contact.php

index e881398df8b9ce893de96f520646934b6117a73c..02f9e829f29f69c341935caf3678617f492fea7f 100644 (file)
@@ -1761,7 +1761,6 @@ class Contact
         * Returns posts from a given contact url
         *
         * @param string $contact_url Contact URL
-        *
         * @param bool   $thread_mode
         * @param int    $update
         * @return string posts in HTML
@@ -1769,9 +1768,21 @@ class Contact
         */
        public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0)
        {
-               $a = DI::app();
+               return self::getPostsFromId(self::getIdForURL($contact_url), $thread_mode, $update);
+       }
 
-               $cid = self::getIdForURL($contact_url);
+       /**
+        * Returns posts from a given contact id
+        *
+        * @param integer $cid
+        * @param bool    $thread_mode
+        * @param integer $update
+        * @return string posts in HTML
+        * @throws \Exception
+        */
+       public static function getPostsFromId($cid, $thread_mode = false, $update = 0)
+       {
+               $a = DI::app();
 
                $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
                if (!DBA::isResult($contact)) {
index cb99492700ce586cc0f111759bd2bcf627afba65..1fb071e53152f9c29beff18c21bce66ed3a56714 100644 (file)
@@ -976,7 +976,12 @@ class Contact extends BaseModule
                        $profiledata = Model\Contact::getDetailsByURL($contact['url']);
 
                        Model\Profile::load($a, '', $profiledata, true);
-                       $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
+
+                       if ($contact['uid'] == 0) {
+                               $o .= Model\Contact::getPostsFromId($contact['id'], true, $update);
+                       } else {
+                               $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
+                       }
                }
 
                return $o;
@@ -998,7 +1003,12 @@ class Contact extends BaseModule
                        }
 
                        Model\Profile::load($a, '', $profiledata, true);
-                       $o .= Model\Contact::getPostsFromUrl($contact['url']);
+
+                       if ($contact['uid'] == 0) {
+                               $o .= Model\Contact::getPostsFromId($contact['id']);
+                       } else {
+                               $o .= Model\Contact::getPostsFromUrl($contact['url']);
+                       }
                }
 
                return $o;