Fixed Trending Content Widget add 11 Querys

  • Thread starter Thread starter DevPunk
  • Start date Start date
XF\Repository\TrendingContentRepository::getResultContent always calls $handler->addAttachmentsToContent($content)

XF\TrendingContent\ThreadHandler
PHP:
public function getEntityWith(string $style): array
{
    $visitor = \XF::visitor();

    $with = [
        'Forum',
        'Forum.Node.Permissions|' . $visitor->permission_combination_id,
        'User',
    ];

    if (in_array($style, ['article', 'carousel'], true))
    {
        $with[] = 'FirstPost';
    }

    return $with;
}

[...]

public function addAttachmentsToContent(AbstractCollection $content): void
{
    $firstPosts = $content
        ->filter(function (Thread $thread): bool
        {
            return $thread->FirstPost !== null;
        })
        ->pluckNamed('FirstPost', 'first_post_id');

So unless the FirstPost entity for a trending thread is already in cache at this point or display style is either Article or Carousel this call causes additional queries for every thread to load that entity.

Suggested Fix
Don't call addAttachmentsToContent unconditionally (Preferred)
or
Unconditionally add FirstPost in getEntityWith
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.3).

Change log:
Reduce trending content widget queries
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom