Permalink
Browse files

Merge pull request #16091 from tgxworld/reduce_creation_of_subscribers

Reduce number of subscriptions created.
  • Loading branch information...
2 parents 05fde24 + b925074 commit cb377455fe9b97e4760d3b7b4af1b1a004a3f14b @spastorino spastorino committed Jul 9, 2014
Showing with 13 additions and 17 deletions.
  1. +13 −17 actionpack/lib/action_controller/test_case.rb
View
30 actionpack/lib/action_controller/test_case.rb
@@ -30,25 +30,21 @@ def setup_subscriptions
end
@_subscribers << ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
- path = payload[:virtual_path]
- next unless path
- partial = path =~ /^.*\/_[^\/]*$/
+ if virtual_path = payload[:virtual_path]
+ partial = virtual_path =~ /^.*\/_[^\/]*$/
- if partial
- @_partials[path] += 1
- @_partials[path.split("/").last] += 1
- end
-
- @_templates[path] += 1
- end
-
- @_subscribers << ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
- next if payload[:virtual_path] # files don't have virtual path
+ if partial
+ @_partials[virtual_path] += 1
+ @_partials[virtual_path.split("/").last] += 1
+ end
- path = payload[:identifier]
- if path
- @_files[path] += 1
- @_files[path.split("/").last] += 1
+ @_templates[virtual_path] += 1
+ else
+ path = payload[:identifier]
+ if path
+ @_files[path] += 1
+ @_files[path.split("/").last] += 1
+ end
end
end
end

0 comments on commit cb37745

Please sign in to comment.