aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable
diff options
context:
space:
mode:
authorLachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au>2015-07-28 15:13:07 +1000
committerLachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au>2015-07-30 10:14:57 +1000
commit60e2fa5e955ce819c90f2081320554b5ed0ee83c (patch)
treefa0c24e3149a06116079c392f3cea3c3928b05de /lib/action_cable
parent65fde3bf75cf82bf18d8cfa36bc07f52c9a866ff (diff)
downloadrails-60e2fa5e955ce819c90f2081320554b5ed0ee83c.tar.gz
rails-60e2fa5e955ce819c90f2081320554b5ed0ee83c.tar.bz2
rails-60e2fa5e955ce819c90f2081320554b5ed0ee83c.zip
refactor channel look up to use a hash instead of an array and reduce the number of calls to safe_constantize because it can be slow
Diffstat (limited to 'lib/action_cable')
-rw-r--r--lib/action_cable/connection/subscriptions.rb4
-rw-r--r--lib/action_cable/server/base.rb4
2 files changed, 3 insertions, 5 deletions
diff --git a/lib/action_cable/connection/subscriptions.rb b/lib/action_cable/connection/subscriptions.rb
index 0411d96413..69e3f60706 100644
--- a/lib/action_cable/connection/subscriptions.rb
+++ b/lib/action_cable/connection/subscriptions.rb
@@ -24,9 +24,7 @@ module ActionCable
id_key = data['identifier']
id_options = ActiveSupport::JSON.decode(id_key).with_indifferent_access
- subscription_klass = connection.server.channel_classes.detect do |channel_class|
- channel_class == id_options[:channel].safe_constantize
- end
+ subscription_klass = connection.server.channel_classes[id_options[:channel]]
if subscription_klass
subscriptions[id_key] ||= subscription_klass.new(connection, id_key, id_options)
diff --git a/lib/action_cable/server/base.rb b/lib/action_cable/server/base.rb
index b09fbf6da4..43849928b9 100644
--- a/lib/action_cable/server/base.rb
+++ b/lib/action_cable/server/base.rb
@@ -36,11 +36,11 @@ module ActionCable
@worker_pool ||= ActionCable::Server::Worker.pool(size: config.worker_pool_size)
end
- # Requires and returns an array of all the channel class constants in this application.
+ # Requires and returns an hash of all the channel class constants keyed by name.
def channel_classes
@channel_classes ||= begin
config.channel_paths.each { |channel_path| require channel_path }
- config.channel_class_names.collect { |name| name.constantize }
+ config.channel_class_names.each_with_object({}) { |name, hash| hash[name] = name.constantize }
end
end