Avoid unneeded database calls when showing posts of contacts

This commit is contained in:
Michael 2020-06-09 22:38:06 +00:00
parent 59bd6fd908
commit 0e9331a1ff
2 changed files with 26 additions and 5 deletions

View file

@ -1761,7 +1761,6 @@ class Contact
* Returns posts from a given contact url * Returns posts from a given contact url
* *
* @param string $contact_url Contact URL * @param string $contact_url Contact URL
*
* @param bool $thread_mode * @param bool $thread_mode
* @param int $update * @param int $update
* @return string posts in HTML * @return string posts in HTML
@ -1769,9 +1768,21 @@ class Contact
*/ */
public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0) 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]); $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {

View file

@ -976,7 +976,12 @@ class Contact extends BaseModule
$profiledata = Model\Contact::getDetailsByURL($contact['url']); $profiledata = Model\Contact::getDetailsByURL($contact['url']);
Model\Profile::load($a, '', $profiledata, true); 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; return $o;
@ -998,7 +1003,12 @@ class Contact extends BaseModule
} }
Model\Profile::load($a, '', $profiledata, true); 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; return $o;