From 211222cc182218c06e9a1b094f48d9e96e905865 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 1 Feb 2019 11:18:35 -0800 Subject: Keep cache for strings in notifications/fanout When adding/removing a subscription with a string pattern, it isn't necessary to clear the entire cache, only the cache for the key being added. When adding/removing subscriptions for a regex or to match all events, the full cache is still cleared. --- activesupport/lib/active_support/notifications/fanout.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 9d7fcef2c7..11721db103 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -24,10 +24,11 @@ module ActiveSupport synchronize do if String === pattern @string_subscribers[pattern] << subscriber + @listeners_for.delete(pattern) else @other_subscribers << subscriber + @listeners_for.clear end - @listeners_for.clear end subscriber end @@ -37,16 +38,17 @@ module ActiveSupport case subscriber_or_name when String @string_subscribers[subscriber_or_name].clear + @listeners_for.delete(subscriber_or_name) else pattern = subscriber_or_name.try(:pattern) if String === pattern @string_subscribers[pattern].delete(subscriber_or_name) + @listeners_for.delete(pattern) else @other_subscribers.delete(subscriber_or_name) + @listeners_for.clear end end - - @listeners_for.clear end end -- cgit v1.2.3