From fc7b2e49b53528b9c460096ea4774c5f1df4d002 Mon Sep 17 00:00:00 2001 From: Fabian Daugs Date: Mon, 25 Nov 2024 15:04:29 +0100 Subject: [PATCH] Compile Regexp on initialization (#63) --- lib/lograge/active_record_log_subscriber.rb | 2 +- lib/lograge/sql.rb | 4 ++-- spec/lograge/active_record_log_subscriber_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/lograge/active_record_log_subscriber.rb b/lib/lograge/active_record_log_subscriber.rb index 11e0be7..33e2f99 100644 --- a/lib/lograge/active_record_log_subscriber.rb +++ b/lib/lograge/active_record_log_subscriber.rb @@ -33,7 +33,7 @@ def filter_query(event) end def valid?(event) - return false if event.payload[:name]&.match?(Regexp.union(Lograge::Sql.query_name_denylist)) + return false if event.payload[:name]&.match?(Lograge::Sql.query_name_denylist) # Only store SQL events if `event.duration` is greater than the configured +min_duration+ # No need to check if +min_duration+ is present before as it defaults to 0 diff --git a/lib/lograge/sql.rb b/lib/lograge/sql.rb index 310d75c..3bd9c4f 100644 --- a/lib/lograge/sql.rb +++ b/lib/lograge/sql.rb @@ -19,12 +19,12 @@ class << self attr_accessor :query_name_denylist # Initialise configuration with fallback to default values - def setup(config) + def setup(config) # rubocop:disable Metrics/AbcSize Lograge::Sql.formatter = config.formatter || default_formatter Lograge::Sql.extract_event = config.extract_event || default_extract_event Lograge::Sql.min_duration_ms = config.min_duration_ms || 0 Lograge::Sql.query_filter = config.query_filter - Lograge::Sql.query_name_denylist = config.query_name_denylist || [/\ASCHEMA\z/, /\ASolidCable::/] + Lograge::Sql.query_name_denylist = Regexp.union(config.query_name_denylist || [/\ASCHEMA\z/, /\ASolidCable::/]) # Disable existing ActiveRecord logging unsubscribe_log_subscribers unless config.keep_default_active_record_log diff --git a/spec/lograge/active_record_log_subscriber_spec.rb b/spec/lograge/active_record_log_subscriber_spec.rb index da0c703..827fe32 100644 --- a/spec/lograge/active_record_log_subscriber_spec.rb +++ b/spec/lograge/active_record_log_subscriber_spec.rb @@ -12,7 +12,7 @@ stub_const('ActiveRecord::RuntimeRegistry', ar_runtime_registry) Lograge::Sql.extract_event = proc {} Lograge::Sql.store.clear - Lograge::Sql.query_name_denylist = [/\ASCHEMA\z/, /\ASolidCable::/] + Lograge::Sql.query_name_denylist = Regexp.union([/\ASCHEMA\z/, /\ASolidCable::/]) end context 'with keep_default_active_record_log not set' do