From 0d3fd854461992a043a21851fedf6b9d554fd79b Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 28 Sep 2023 15:26:12 -0700 Subject: [PATCH] Made minor updates --- gems/aws-sdk-sqs/lib/aws-sdk-sqs/queue_poller.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/gems/aws-sdk-sqs/lib/aws-sdk-sqs/queue_poller.rb b/gems/aws-sdk-sqs/lib/aws-sdk-sqs/queue_poller.rb index 3a21c69c41a..42b8ea70144 100644 --- a/gems/aws-sdk-sqs/lib/aws-sdk-sqs/queue_poller.rb +++ b/gems/aws-sdk-sqs/lib/aws-sdk-sqs/queue_poller.rb @@ -401,7 +401,11 @@ def check_idle_timeout(config, stats) def process_messages(config, stats, messages, &block) stats.received_message_count += messages.count stats.last_message_received_at = Time.now - messages = dedupe_messages(messages) + + # duplicated messages will have a different receipt handle + # so we need to provide the most recent receipt to + # delete a batch - thus, filtering below by message_id + messages = messages.reverse.uniq(&:message_id).reverse! catch(:skip_delete) do yield_messages(config, messages, stats, &block) delete_messages(messages) unless config.skip_delete @@ -418,16 +422,6 @@ def yield_messages(config, messages, stats, &block) end end - def dedupe_messages(messages) - # duplicate messages will have a different receipt handle - # so must provide the most recently receipt handle - # when deleting the message - messages.each_with_object({}) do |msg, unique| - unique[msg.message_id] = msg - unique - end.values - end - # Statistics tracked client-side by the {QueuePoller}. class PollerStats def initialize