Fixed N+1 query behaviour when bulk indexing profile post comments

Affected version
2.1.3

Xon

Well-known member
Because of the if check in `getIndexData, the profile user is being loaded for every profile post when bulk-indexing.
PHP:
    public function getIndexData(Entity $entity)
    {
        /** @var \XF\Entity\ProfilePostComment $entity */

        if (!$entity->ProfilePost || !$entity->ProfilePost->ProfileUser)
        {
            return null;
        }
...
Simple fix would be to change getEntityWith to have it in the with clause;
PHP:
    public function getEntityWith($forView = false)
    {
        $get = ['ProfilePost','ProfilePost.ProfileUser'];
...
       return $get;
    }
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.4).

Change log:
When indexing profile post comments, reduce the number of queries.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top