mirror of
https://github.com/friendica/friendica
synced 2024-11-14 03:42:53 +00:00
Reduce the amount of queries
This commit is contained in:
parent
aa65e3032d
commit
1326239576
2 changed files with 21 additions and 17 deletions
|
@ -108,6 +108,8 @@ class Conversation
|
||||||
*/
|
*/
|
||||||
public function builtinActivityPuller(array $activity, array &$conv_responses)
|
public function builtinActivityPuller(array $activity, array &$conv_responses)
|
||||||
{
|
{
|
||||||
|
$thread_parent = $activity['thr-parent-row'] ?? [];
|
||||||
|
|
||||||
foreach ($conv_responses as $mode => $v) {
|
foreach ($conv_responses as $mode => $v) {
|
||||||
$sparkle = '';
|
$sparkle = '';
|
||||||
|
|
||||||
|
@ -152,9 +154,8 @@ class Conversation
|
||||||
$activity['thr-parent-id'] = $activity['parent-uri-id'];
|
$activity['thr-parent-id'] = $activity['parent-uri-id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip when the causer of the parent is the same than the author of the announce
|
// Skip when the causer of the parent is the same as the author of the announce
|
||||||
if (($verb == Activity::ANNOUNCE) && Post::exists(['uri-id' => $activity['thr-parent-id'],
|
if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id'] && ($thread_parent['causer-id'] == $activity['author-id']))) {
|
||||||
'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,10 +812,11 @@ class Conversation
|
||||||
*
|
*
|
||||||
* @param array $row Post row
|
* @param array $row Post row
|
||||||
* @param array $activity Contact data of the resharer
|
* @param array $activity Contact data of the resharer
|
||||||
|
* @param array $thr_parent Thread parent row
|
||||||
*
|
*
|
||||||
* @return array items with parents and comments
|
* @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');
|
$this->profiler->startRecording('rendering');
|
||||||
|
|
||||||
|
@ -889,6 +891,8 @@ class Conversation
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$row['thr-parent-row'] = $thr_parent;
|
||||||
|
|
||||||
$this->profiler->stopRecording();
|
$this->profiler->stopRecording();
|
||||||
return $row;
|
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);
|
$thread_items = Post::selectForUser($uid, array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
|
||||||
|
|
||||||
$items = [];
|
$items = [];
|
||||||
|
$thr_parent = [];
|
||||||
|
|
||||||
while ($row = Post::fetch($thread_items)) {
|
while ($row = Post::fetch($thread_items)) {
|
||||||
if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
|
if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
|
||||||
|
@ -968,7 +973,12 @@ class Conversation
|
||||||
continue;
|
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);
|
DBA::close($thread_items);
|
||||||
|
|
|
@ -29,7 +29,6 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Database\DBA;
|
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
|
@ -898,12 +897,7 @@ class Post
|
||||||
}
|
}
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($a->getLoggedInUserId());
|
$owner = User::getOwnerDataById($a->getLoggedInUserId());
|
||||||
|
$item = $this->getData();
|
||||||
$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 '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
|
if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
|
||||||
$text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
|
$text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
|
||||||
|
@ -967,7 +961,7 @@ class Post
|
||||||
$uid = $conv->getProfileOwner();
|
$uid = $conv->getProfileOwner();
|
||||||
$parent_uid = $this->getDataValue('uid');
|
$parent_uid = $this->getDataValue('uid');
|
||||||
|
|
||||||
$contact = Contact::getById($a->getContactId());
|
$owner = User::getOwnerDataById($a->getLoggedInUserId());
|
||||||
|
|
||||||
$default_text = $this->getDefaultText();
|
$default_text = $this->getDefaultText();
|
||||||
|
|
||||||
|
@ -986,9 +980,9 @@ class Post
|
||||||
'$qcomment' => $qcomment,
|
'$qcomment' => $qcomment,
|
||||||
'$default' => $default_text,
|
'$default' => $default_text,
|
||||||
'$profile_uid' => $uid,
|
'$profile_uid' => $uid,
|
||||||
'$mylink' => DI::baseUrl()->remove($contact['url'] ?? ''),
|
'$mylink' => DI::baseUrl()->remove($owner['url'] ?? ''),
|
||||||
'$mytitle' => DI::l10n()->t('This is you'),
|
'$mytitle' => DI::l10n()->t('This is you'),
|
||||||
'$myphoto' => DI::baseUrl()->remove($contact['thumb'] ?? ''),
|
'$myphoto' => DI::baseUrl()->remove($owner['thumb'] ?? ''),
|
||||||
'$comment' => DI::l10n()->t('Comment'),
|
'$comment' => DI::l10n()->t('Comment'),
|
||||||
'$submit' => DI::l10n()->t('Submit'),
|
'$submit' => DI::l10n()->t('Submit'),
|
||||||
'$loading' => DI::l10n()->t('Loading...'),
|
'$loading' => DI::l10n()->t('Loading...'),
|
||||||
|
|
Loading…
Reference in a new issue