Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8559 from mshytikov/runner_method_is_slow_with_th…

…read_safe

Attempt to fix slow runner name method
  • Loading branch information...
commit b225693a0d86f2e33c66049a69e5148e5c93b7cd 2 parents 939ff86 + 5c33542
@josevalim josevalim authored
Showing with 10 additions and 1 deletion.
  1. +10 −1 activesupport/lib/active_support/callbacks.rb
View
11 activesupport/lib/active_support/callbacks.rb
@@ -1,3 +1,4 @@
+require 'thread_safe'
require 'active_support/concern'
require 'active_support/descendants_tracker'
require 'active_support/core_ext/class/attribute'
@@ -351,10 +352,18 @@ def __reset_runner(symbol)
undef_method(name) if method_defined?(name)
end
- def __callback_runner_name(kind)
+ def __callback_runner_name_cache
+ @__callback_runner_name_cache ||= ThreadSafe::Cache.new {|cache, kind| cache[kind] = __generate_callback_runner_name(kind) }
+ end
+
+ def __generate_callback_runner_name(kind)
"_run__#{self.name.hash.abs}__#{kind}__callbacks"
end
+ def __callback_runner_name(kind)
+ __callback_runner_name_cache[kind]
+ end
+
# This is used internally to append, prepend and skip callbacks to the
# CallbackChain.
def __update_callbacks(name, filters = [], block = nil) #:nodoc:
Please sign in to comment.
Something went wrong with that request. Please try again.