aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2015-07-30 07:33:13 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2015-07-30 07:33:13 +0200
commit0c30d87868a8b59c47acbc695ef5e37d6361b3cc (patch)
treefa0c24e3149a06116079c392f3cea3c3928b05de /lib/action_cable
parent65fde3bf75cf82bf18d8cfa36bc07f52c9a866ff (diff)
parent60e2fa5e955ce819c90f2081320554b5ed0ee83c (diff)
downloadrails-0c30d87868a8b59c47acbc695ef5e37d6361b3cc.tar.gz
rails-0c30d87868a8b59c47acbc695ef5e37d6361b3cc.tar.bz2
rails-0c30d87868a8b59c47acbc695ef5e37d6361b3cc.zip
Merge pull request #42 from lsylvester/channel-lookup-refactor
Optimize channel class lookup
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