From 2ff0938fa6c2aef1ef326c6321d00985f356b656 Mon Sep 17 00:00:00 2001 From: Damian Dziaduch Date: Fri, 27 Jan 2023 17:38:00 +0100 Subject: [PATCH] Add combined index With multiple queues and thousands of messages, MongoDB is doing a full collection scan. The combined index solves that. --- pkg/mongodb/MongodbContext.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/mongodb/MongodbContext.php b/pkg/mongodb/MongodbContext.php index e6f5a579c..2e52ebdb2 100644 --- a/pkg/mongodb/MongodbContext.php +++ b/pkg/mongodb/MongodbContext.php @@ -161,5 +161,6 @@ public function createCollection(): void $collection->createIndex(['queue' => 1], ['name' => 'enqueue_queue']); $collection->createIndex(['priority' => -1, 'published_at' => 1], ['name' => 'enqueue_priority']); $collection->createIndex(['delayed_until' => 1], ['name' => 'enqueue_delayed']); + $collection->createIndex(['queue' => 1, 'priority' => -1, 'published_at' => 1, 'delayed_until' => 1], ['name' => 'enqueue_combined']); } }