From 82c57cd36a800d08ec71ed26d284b58e09c2428a Mon Sep 17 00:00:00 2001 From: Ian Morland Date: Wed, 13 Jan 2021 19:18:38 +0000 Subject: [PATCH] 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). --- ..._add_discussion_last_posted_at_indices.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 extensions/sticky/migrations/2021_01_13_000000_add_discussion_last_posted_at_indices.php diff --git a/extensions/sticky/migrations/2021_01_13_000000_add_discussion_last_posted_at_indices.php b/extensions/sticky/migrations/2021_01_13_000000_add_discussion_last_posted_at_indices.php new file mode 100644 index 000000000..a837fdddf --- /dev/null +++ b/extensions/sticky/migrations/2021_01_13_000000_add_discussion_last_posted_at_indices.php @@ -0,0 +1,25 @@ + 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']); + }); + } +];