aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-07-14 15:20:31 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-08-04 10:45:30 +0900
commit242348ad682950fb6bf1f47877068cc23ba95879 (patch)
tree04a25b1a674785ffa7c1c28805440f79d872d438 /activerecord/lib/active_record/core.rb
parent050bbb1f3329bd4fe7740e7feb572e95c246d49e (diff)
downloadrails-242348ad682950fb6bf1f47877068cc23ba95879.tar.gz
rails-242348ad682950fb6bf1f47877068cc23ba95879.tar.bz2
rails-242348ad682950fb6bf1f47877068cc23ba95879.zip
Use `Concurrent::Map` than `Mutex` and `Mutex_m` for statement caches
Statement caches are used as a concurrent map. It will more clarify to using `Concurrent::Map`.
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r--activerecord/lib/active_record/core.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 5d673339cf..fbb4c671a5 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -2,6 +2,7 @@
require "active_support/core_ext/hash/indifferent_access"
require "active_support/core_ext/string/filters"
+require "concurrent/map"
module ActiveRecord
module Core
@@ -149,7 +150,7 @@ module ActiveRecord
end
def initialize_find_by_cache # :nodoc:
- @find_by_statement_cache = { true => {}.extend(Mutex_m), false => {}.extend(Mutex_m) }
+ @find_by_statement_cache = { true => Concurrent::Map.new, false => Concurrent::Map.new }
end
def inherited(child_class) # :nodoc:
@@ -281,9 +282,7 @@ module ActiveRecord
def cached_find_by_statement(key, &block)
cache = @find_by_statement_cache[connection.prepared_statements]
- cache[key] || cache.synchronize {
- cache[key] ||= StatementCache.create(connection, &block)
- }
+ cache.compute_if_absent(key) { StatementCache.create(connection, &block) }
end
def relation