Unnesessary query for non-mirrored media items

Kirby

Well-known member
Affected version
2.2.4
In XF\Pub\Controller\Media::actionIndex
PHP:
$mirrorAttachment = $mediaItem->MirrorAttachment;

This does gall get getMirrorAttachment on the entity which moreless unconditionally issues a query:
PHP:
public function getMirrorAttachment()
{
    $attachment = $this->Attachment;
    if (!$attachment)
    {
        return null;
    }

    return $this->_em->findOne('XF:Attachment', [
        'data_id' => $attachment->data_id,
        'xfmg_is_mirror_handler' => 1
    ]);
}

This query seems useless for non-mirrored media items as it will never return a result.
Especially if there are no mirrored media items at all (which at least I would envision to be a pretty common scenario) this seems wasteful and should be avoided.
 
Top Bottom