Permalink
Browse files

Minor performance improvment in notifications/fanout and active_recor…

…d/log_subscriber [#5098 state:open]
  • Loading branch information...
dguettler authored and tenderlove committed Jul 18, 2010
1 parent ad4ef42 commit 38f0161aabb302550e1522cb62d19e54d448be9b
@@ -6,6 +6,8 @@ def initialize
end
def sql(event)
+ return unless logger.debug?
+
name = '%s (%.1fms)' % [event.payload[:name], event.duration]
sql = event.payload[:sql].squeeze(' ')
@@ -21,11 +21,11 @@ def unsubscribe(subscriber)
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 @@ def initialize(pattern, delegate)
end
def publish(message, *args)
- return unless subscribed_to?(message)
@delegate.call(message, *args)
- true
end
def subscribed_to?(name)

0 comments on commit 38f0161

Please sign in to comment.