Reduce the amount of queries

This commit is contained in:
Michael 2022-04-29 05:32:12 +00:00
parent aa65e3032d
commit 1326239576
2 changed files with 21 additions and 17 deletions

View File

@ -108,6 +108,8 @@ class Conversation
*/
public function builtinActivityPuller(array $activity, array &$conv_responses)
{
$thread_parent = $activity['thr-parent-row'] ?? [];
foreach ($conv_responses as $mode => $v) {
$sparkle = '';
@ -152,9 +154,8 @@ class Conversation
$activity['thr-parent-id'] = $activity['parent-uri-id'];
}
// Skip when the causer of the parent is the same than the author of the announce
if (($verb == Activity::ANNOUNCE) && Post::exists(['uri-id' => $activity['thr-parent-id'],
'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
// Skip when the causer of the parent is the same as the author of the announce
if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id'] && ($thread_parent['causer-id'] == $activity['author-id']))) {
continue;
}
@ -809,12 +810,13 @@ class Conversation
/**
* Adds some information (Causer, post reason, direction) to the fetched post row.
*
* @param array $row Post row
* @param array $activity Contact data of the resharer
* @param array $row Post row
* @param array $activity Contact data of the resharer
* @param array $thr_parent Thread parent row
*
* @return array items with parents and comments
*/
private function addRowInformation(array $row, array $activity)
private function addRowInformation(array $row, array $activity, array $thr_parent)
{
$this->profiler->startRecording('rendering');
@ -889,6 +891,8 @@ class Conversation
break;
}
$row['thr-parent-row'] = $thr_parent;
$this->profiler->stopRecording();
return $row;
}
@ -954,6 +958,7 @@ class Conversation
$thread_items = Post::selectForUser($uid, array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
$items = [];
$thr_parent = [];
while ($row = Post::fetch($thread_items)) {
if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
@ -968,7 +973,12 @@ class Conversation
continue;
}
}
$items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? []);
if (empty($thr_parent[$row['thr-parent-id']])) {
$thr_parent[$row['thr-parent-id']] = Post::selectFirst(['causer-id'], ['uri-id' => $row['thr-parent-id'], 'uid' => $row['uid']]);
}
$items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? [], $thr_parent[$row['thr-parent-id']]);
}
DBA::close($thread_items);

View File

@ -29,7 +29,6 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
@ -898,12 +897,7 @@ class Post
}
$owner = User::getOwnerDataById($a->getLoggedInUserId());
$item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity', 'content-warning'], ['id' => $this->getId()]);
if (!DBA::isResult($item) || empty($item['author-addr'])) {
// Should not happen
return '';
}
$item = $this->getData();
if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
$text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
@ -967,7 +961,7 @@ class Post
$uid = $conv->getProfileOwner();
$parent_uid = $this->getDataValue('uid');
$contact = Contact::getById($a->getContactId());
$owner = User::getOwnerDataById($a->getLoggedInUserId());
$default_text = $this->getDefaultText();
@ -986,9 +980,9 @@ class Post
'$qcomment' => $qcomment,
'$default' => $default_text,
'$profile_uid' => $uid,
'$mylink' => DI::baseUrl()->remove($contact['url'] ?? ''),
'$mylink' => DI::baseUrl()->remove($owner['url'] ?? ''),
'$mytitle' => DI::l10n()->t('This is you'),
'$myphoto' => DI::baseUrl()->remove($contact['thumb'] ?? ''),
'$myphoto' => DI::baseUrl()->remove($owner['thumb'] ?? ''),
'$comment' => DI::l10n()->t('Comment'),
'$submit' => DI::l10n()->t('Submit'),
'$loading' => DI::l10n()->t('Loading...'),