New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Maintenance] Optimize tables with full text indexes periodically #11817
[Maintenance] Optimize tables with full text indexes periodically #11817
Conversation
LGTM, but tasks need to be registered as services, see:
Can you please update your PR accordingly? |
Sorry, forgot the service. Is fixed now. |
👍 Thanks! |
Just as a note: I tried to migrate this maintenance task to a Pimcore 6.9 system (with
There I changed the calls in pimcore/lib/Maintenance/Tasks/FullTextIndexOptimizeTask.php Lines 41 to 42 in ffe18e9
to use fetchAll() instead of exec() and this works. Do not know what caused the error but if this ever occurs also for Pimcore 10, this may become useful...
|
We just upgraded to Pimcore 10 and had this issue. Can be solved by overriding the class: <?php
namespace Pimcore\Maintenance\Tasks;
use Pimcore\Db;
use Pimcore\Maintenance\TaskInterface;
use Symfony\Component\Lock\LockFactory;
/**
* @internal
*/
class FullTextIndexOptimizeTask implements TaskInterface
{
/** @var \Symfony\Component\Lock\LockInterface */
private $lock;
public function __construct(LockFactory $lockFactory)
{
$this->lock = $lockFactory->createLock(self::class, 86400 * 7, false);
}
/**
* {@inheritdoc}
*/
public function execute()
{
// Override to make it work
// See: https://github.com/pimcore/pimcore/pull/11817#issuecomment-1105026544
if ($this->lock->acquire(false)) {
Db::get()->fetchAll('OPTIMIZE TABLE search_backend_data');
Db::get()->fetchAll('OPTIMIZE TABLE email_log');
}
}
} And then in your "psr-4": {
"App\\": "src/",
"Pimcore\\Maintenance\\Tasks\\": "overrides/Pimcore/Maintenance/Tasks",
} |
Full text indexes get slower over time because of gaps caused by deleting entries and because word counts get fragmented. In a concrete case we had the problem of ~600K entries in
search_backend_data
and the querytook 28 seconds.
This gets used in
pimcore/bundles/AdminBundle/Helper/GridHelperService.php
Line 617 in f415841
and also in other places like object search.
After running
OPTIMIZE TABLE search_backend_data
this same query takes 0.1 seconds.
It is even documented in the MySQL docs: https://dev.mysql.com/doc/refman/8.0/en/fulltext-fine-tuning.html#fulltext-optimize
This PR adds a maintenance task which optimizes the tables with fulltext indexes once every 7 days - currently those are
search_backend_data
andemail_log
. I also thought about fetching all tables which have fulltext indexes and optimize those but this would pull control of third-party tables like from plugins or application-specific implementation away from the owners.