From c3c07f6aabd078b874704aeca4632278b8d5f2bd Mon Sep 17 00:00:00 2001 From: Andrzej Bisewski <152981096+andrzejbisewski@users.noreply.github.com> Date: Fri, 29 Aug 2025 12:53:55 +0200 Subject: [PATCH 1/3] Memoize SNS client --- lib/eventboss/sns_client.rb | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/eventboss/sns_client.rb b/lib/eventboss/sns_client.rb index b5cbf4f..7f53915 100644 --- a/lib/eventboss/sns_client.rb +++ b/lib/eventboss/sns_client.rb @@ -39,25 +39,27 @@ def set_raw_message_delivery(subscription) end def backend - if configured? - options = { - region: configuration.eventboss_region, - } - - unless configuration.eventboss_use_default_credentials - options[:credentials] = credentials - end - - if configuration.aws_sns_endpoint - options[:endpoint] = configuration.aws_sns_endpoint - end - - Aws::SNS::Client.new(options) - elsif configuration.raise_on_missing_configuration - raise NotConfigured, 'Eventboss is not configured.' - else - Mock.new - end + @backend ||= begin + if configured? + options = { + region: configuration.eventboss_region, + } + + unless configuration.eventboss_use_default_credentials + options[:credentials] = credentials + end + + if configuration.aws_sns_endpoint + options[:endpoint] = configuration.aws_sns_endpoint + end + + Aws::SNS::Client.new(options) + elsif configuration.raise_on_missing_configuration + raise NotConfigured, 'Eventboss is not configured.' + else + Mock.new + end + end end def credentials From 71c3029bcec0e2d71e81b5b36362699c53fc60d3 Mon Sep 17 00:00:00 2001 From: Andrzej Bisewski <152981096+andrzejbisewski@users.noreply.github.com> Date: Tue, 9 Sep 2025 12:46:18 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ lib/eventboss/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f2af3d..dbdd00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.9.8] + +- Improve performance by reusing SNS client + ## [1.9.7] - Fix undefined method 'set_data' for nil span in Sentry integration diff --git a/lib/eventboss/version.rb b/lib/eventboss/version.rb index 3ef73d1..b1c4410 100644 --- a/lib/eventboss/version.rb +++ b/lib/eventboss/version.rb @@ -1,3 +1,3 @@ module Eventboss - VERSION = "1.9.7" + VERSION = "1.9.8" end From 4b56346eed655c744bf6501f5d1aa4275c524bcb Mon Sep 17 00:00:00 2001 From: Andrzej Bisewski <152981096+andrzejbisewski@users.noreply.github.com> Date: Wed, 10 Sep 2025 15:25:39 +0200 Subject: [PATCH 3/3] rubocop that function --- lib/eventboss/sns_client.rb | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/eventboss/sns_client.rb b/lib/eventboss/sns_client.rb index 7f53915..66413e1 100644 --- a/lib/eventboss/sns_client.rb +++ b/lib/eventboss/sns_client.rb @@ -39,27 +39,22 @@ def set_raw_message_delivery(subscription) end def backend - @backend ||= begin - if configured? - options = { - region: configuration.eventboss_region, - } - - unless configuration.eventboss_use_default_credentials - options[:credentials] = credentials - end - - if configuration.aws_sns_endpoint - options[:endpoint] = configuration.aws_sns_endpoint - end - - Aws::SNS::Client.new(options) - elsif configuration.raise_on_missing_configuration - raise NotConfigured, 'Eventboss is not configured.' - else - Mock.new - end - end + @backend ||= + if configured? + options = { + region: configuration.eventboss_region + } + + options[:credentials] = credentials unless configuration.eventboss_use_default_credentials + + options[:endpoint] = configuration.aws_sns_endpoint if configuration.aws_sns_endpoint + + Aws::SNS::Client.new(options) + elsif configuration.raise_on_missing_configuration + raise NotConfigured, 'Eventboss is not configured.' + else + Mock.new + end end def credentials