XF 2.1 Rebuild Processes

Ozzy47

Well-known member
In my setup file I have this:
PHP:
    public function installStep1()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildPostMentions',
            [],
            true
        );
    }

    public function installStep2()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildConversationMessageMentions',
            [],
            true
        );
    }

    public function installStep3()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildProfilePostMentions',
            [],
            true
        );
    }

    public function installStep4()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildProfilePostCommentMentions',
            [],
            true
        );
    }

    public function upgrade1000170Step1()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildPostMentions',
            [],
            true
        );
    }

    public function upgrade1000170Step2()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildConversationMessageMentions',
            [],
            true
        );
    }

    public function upgrade1000170Step3()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildProfilePostMentions',
            [],
            true
        );
    }

    public function upgrade1000170Step4()
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatar-' . __FUNCTION__,
            'LiamW\MentionMiniAvatar:RebuildProfilePostCommentMentions',
            [],
            true
        );
    }

Then in my job files, they look like this, (I will show the rebulld post mentions as an example):
PHP:
class RebuildPostMentions extends AbstractRebuildMentions
{
    /**
     * @return string
     */
    protected function getContentType()
    {
        return 'post';
    }
}

Now when installing the addon, or upgrading, I see large query counts and memory usage, 80000 - 8600 queries, and memory usage 20.00 - 30.00 mb screenshot below
Screenshot_2020-03-10-20-31-47.webp

This is on a dev site with about 11,000 posts. My question is, is this something that is normal,? Should I be concerned about slowing down someones site doing this?
 
I'd recommend stuffing all 4 of those calls into postInstall instead like so:

PHP:
    public function postInstall(array &$stateChanges)
    {
        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatarPost',
            'LiamW\MentionMiniAvatar:RebuildPostMentions',
            [],
            false
        );

        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatarConversation',
            'LiamW\MentionMiniAvatar:RebuildConversationMessageMentions',
            [],
            false
        );

        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatarProfilePost',
            'LiamW\MentionMiniAvatar:RebuildProfilePostMentions',
            [],
            false
        );

        $this->jobManager()->enqueueUnique(
            'liamWMentionMiniAvatarProfilePostComment',
            'LiamW\MentionMiniAvatar:RebuildProfilePostCommentMentions',
            [],
            false
        );
    }

Then do the same for postUpgrade like so:
PHP:
    public function postUpgrade($previousVersion, array &$stateChanges)
    {
        if ($previousVersion < 1000170)
        {
            $this->jobManager()->enqueueUnique(
                'liamWMentionMiniAvatarPost',
                'LiamW\MentionMiniAvatar:RebuildPostMentions',
                [],
                false
            );

            $this->jobManager()->enqueueUnique(
                'liamWMentionMiniAvatarConversation',
                'LiamW\MentionMiniAvatar:RebuildConversationMessageMentions',
                [],
                false
            );

            $this->jobManager()->enqueueUnique(
                'liamWMentionMiniAvatarProfilePost',
                'LiamW\MentionMiniAvatar:RebuildProfilePostMentions',
                [],
                false
            );

            $this->jobManager()->enqueueUnique(
                'liamWMentionMiniAvatarProfilePostComment',
                'LiamW\MentionMiniAvatar:RebuildProfilePostCommentMentions',
                [],
                false
            );
        }
    }
That way, these things can run in the background and won't require admins to sit around for potentially ages waiting for rebuild actions to run.
 
Back
Top Bottom