Add is_sticky, last_posted_at index to improve performance (#23)

This PR introduces an additional index [is_sticky, last_posted_at] to the discussions table. We discovered that when viewing discussions in a tag with a large number of discussions (approx 1.4M in our case), performance was poor when using the default sort criteria (sort by latest).
This commit is contained in:
Ian Morland 2021-01-13 19:18:38 +00:00 committed by GitHub
parent 8e3e51a613
commit 82c57cd36a

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) {
$table->index(['is_sticky', 'last_posted_at']);
});
},
'down' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) {
$table->dropIndex(['is_sticky', 'last_posted_at']);
});
}
];