Skip to content

Commit

Permalink
Compile Regexp on initialization (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdaugs authored Nov 25, 2024
1 parent 7ad0ced commit fc7b2e4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/lograge/active_record_log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/lograge/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lograge/active_record_log_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc7b2e4

Please sign in to comment.