Merge pull request #8752 from annando/posts-from-id

Avoid unneeded database calls when showing posts of contacts
This commit is contained in:
Hypolite Petovan 2020-06-10 00:11:51 -04:00 committed by GitHub
commit 5f18d27b0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View 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)) {

View 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;