From 2247817d1e3771eeb277a013b8ed7ea7fdb4304a Mon Sep 17 00:00:00 2001 From: Daniel Guettler Date: Sun, 18 Jul 2010 07:30:48 -0400 Subject: [PATCH] Minor performance improvment in notifications/fanout and active_record/log_subscriber [#5098 state:open] --- activerecord/lib/active_record/log_subscriber.rb | 2 ++ .../lib/active_support/notifications/fanout.rb | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 89c7905..278e192 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -6,6 +6,8 @@ module ActiveRecord end def sql(event) + return unless logger.debug? + name = '%s (%.1fms)' % [event.payload[:name], event.duration] sql = event.payload[:sql].squeeze(' ') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 526ca26..64f315c 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -21,11 +21,11 @@ module ActiveSupport end def publish(name, *args) - if listeners = @listeners_for[name] - listeners.each { |s| s.publish(name, *args) } - else - @listeners_for[name] = @subscribers.select { |s| s.publish(name, *args) } - end + listeners_for(name).each { |s| s.publish(name, *args) } + end + + def listeners_for(name) + @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } end # This is a sync queue, so there is not waiting. @@ -39,9 +39,7 @@ module ActiveSupport end def publish(message, *args) - return unless subscribed_to?(message) @delegate.call(message, *args) - true end def subscribed_to?(name) -- 1.5.6