diff --git a/changelog.d/5-internal/efficient-queue-listing b/changelog.d/5-internal/efficient-queue-listing new file mode 100644 index 00000000000..d451e269aec --- /dev/null +++ b/changelog.d/5-internal/efficient-queue-listing @@ -0,0 +1 @@ +List queues for backend notifications more efficiently. \ No newline at end of file diff --git a/integration/test/Testlib/ResourcePool.hs b/integration/test/Testlib/ResourcePool.hs index aa518939fef..83bd1499a84 100644 --- a/integration/test/Testlib/ResourcePool.hs +++ b/integration/test/Testlib/ResourcePool.hs @@ -89,7 +89,7 @@ deleteAllRabbitMQQueues rc resource = do tls = Just $ RabbitMqTlsOpts Nothing True } client <- mkRabbitMqAdminClientEnv opts - queues <- listQueuesByVHost client (T.pack resource.berVHost) + queues <- listQueuesByVHost client (T.pack resource.berVHost) Nothing Nothing for_ queues $ \queue -> deleteQueue client (T.pack resource.berVHost) queue.name diff --git a/libs/extended/src/Network/RabbitMqAdmin.hs b/libs/extended/src/Network/RabbitMqAdmin.hs index 68251f97f23..77d65afc676 100644 --- a/libs/extended/src/Network/RabbitMqAdmin.hs +++ b/libs/extended/src/Network/RabbitMqAdmin.hs @@ -24,6 +24,8 @@ data AdminAPI route = AdminAPI :- "api" :> "queues" :> Capture "vhost" VHost + :> QueryParam "name" Text + :> QueryParam "use_regex" Bool :> Get '[JSON] [Queue], deleteQueue :: route diff --git a/services/background-worker/src/Wire/BackendNotificationPusher.hs b/services/background-worker/src/Wire/BackendNotificationPusher.hs index f055ed0b492..68f9e25dd54 100644 --- a/services/background-worker/src/Wire/BackendNotificationPusher.hs +++ b/services/background-worker/src/Wire/BackendNotificationPusher.hs @@ -282,7 +282,7 @@ getRemoteDomains adminClient = do go :: AppT IO [Domain] go = do vhost <- asks rabbitmqVHost - queues <- liftIO $ listQueuesByVHost adminClient vhost + queues <- liftIO $ listQueuesByVHost adminClient vhost (Just "backend-notifications\\..*") (Just True) let notifQueuesSuffixes = mapMaybe (\q -> Text.stripPrefix "backend-notifications." q.name) queues catMaybes <$> traverse (\d -> either (\e -> logInvalidDomain d e >> pure Nothing) (pure . Just) $ mkDomain d) notifQueuesSuffixes logInvalidDomain d e = diff --git a/services/background-worker/test/Test/Wire/BackendNotificationPusherSpec.hs b/services/background-worker/test/Test/Wire/BackendNotificationPusherSpec.hs index 72e1a17840f..322ccddd148 100644 --- a/services/background-worker/test/Test/Wire/BackendNotificationPusherSpec.hs +++ b/services/background-worker/test/Test/Wire/BackendNotificationPusherSpec.hs @@ -351,8 +351,8 @@ mockApi mockAdmin = deleteQueue = mockListDeleteQueue mockAdmin } -mockListQueuesByVHost :: MockRabbitMqAdmin -> Text -> Servant.Handler [Queue] -mockListQueuesByVHost MockRabbitMqAdmin {..} vhost = do +mockListQueuesByVHost :: MockRabbitMqAdmin -> Text -> Maybe Text -> Maybe Bool -> Servant.Handler [Queue] +mockListQueuesByVHost MockRabbitMqAdmin {..} vhost _ _ = do atomically $ modifyTVar listQueuesVHostCalls (<> [vhost]) readTVarIO broken >>= \case True -> throwError $ Servant.err500