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

Xon

Well-known member
Affected version
2.1.3
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;
    }
 
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.
 
Back
Top Bottom