• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Implemented Rebuild Caches through CLI

Alfa1

Well-known member
#1
Now that we have a CLI tool to install and upgrade addons, I would like to request a function to Rebuild Caches through CLI.
This allows us to simply initiate the task and get on with whatever we need to do. No need to wait for deferred to complete.

What I mean by this is any task that is in XF1 here: /admin.php?tools/rebuild
 
Last edited:

Jake B.

Well-known member
#2
Yeah, something like this would be a life saver. Especially when rebuilding search index takes countless hours without Enhanced Search
 

Chris D

XenForo developer
Staff member
#3
We've added the ability to rebuild various things via the CLI using the following commands as of the next release (a mix of XF and add-on rebuilds here):
Code:
    xf-rebuild:xfrm-user-resource-counts
    xf-rebuild:xfrm-resource-items
    xf-rebuild:xfmg-media-items
    xf-rebuild:xfmg-user-counts
    xf-rebuild:xfmg-albums
    xf-rebuild:threads
    xf-rebuild:search
    xf-rebuild:forums
    xf-rebuild:users
This is only a selected portion of the available rebuilds (the important ones), though we could add more in the future, and doing so is crazily simple. As an example, here's the rebuild forums command class:
PHP:
<?php

namespace XF\Cli\Command\Rebuild;

class RebuildForums extends AbstractRebuildCommand
{
    protected function getRebuildName()
    {
        return 'forums';
    }

    protected function getRebuildDescription()
    {
        return 'Rebuilds forum counters.';
    }

    protected function getRebuildClass()
    {
        return 'XF:Forum';
    }
}
 

Xon

Well-known member
#6
@Chris D Any change you can alter the rebuild logic for the CLI rebuild logic + search handler to work down from a known maximum id? (ie the entity does a select max(primary-id) from table).

This makes it easy to fork a bunch and hand out known id-range batch sizes with the stop check being a simple >0 id check without any additional queries.

I'm using a hacky version of this approach for my XF1 Elastic Search Essentials add-on, and it is a 3-3.5 times speedup with 4 worker processes. Which helps massively with +20 million posts.
 
Last edited:

Chris D

XenForo developer
Staff member
#7
That would have to be a totally separate suggestion.

The job command code itself just essentially calls the normal job and runs it in a loop so there's not particularly anything we can do in the command class itself.