aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 70d88e561b..9e3c54c7d4 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -310,7 +310,7 @@ module ActiveRecord #:nodoc:
# Determines whether or not to use a connection for each thread, or a single shared connection for all threads.
# Defaults to false. Set to true if you're writing a threaded application.
cattr_accessor :allow_concurrency
- @@allow_concurrency = true
+ @@allow_concurrency = false
# Determines whether to speed up access by generating optimized reader
# methods to avoid expensive calls to method_missing when accessing
@@ -1140,15 +1140,22 @@ module ActiveRecord #:nodoc:
end
end
- def scoped_methods
- if allow_concurrency
- Thread.current[:scoped_methods] ||= {}
- Thread.current[:scoped_methods][self] ||= []
- else
- @scoped_methods ||= []
- end
+ def thread_safe_scoped_methods #:nodoc:
+ scoped_methods = (Thread.current[:scoped_methods] ||= {})
+ scoped_methods[self] ||= []
end
-
+
+ def single_threaded_scoped_methods #:nodoc:
+ @scoped_methods ||= []
+ end
+
+ # pick up the correct scoped_methods version from @@allow_concurrency
+ if @@allow_concurrency
+ alias_method :scoped_methods, :thread_safe_scoped_methods
+ else
+ alias_method :scoped_methods, :single_threaded_scoped_methods
+ end
+
def current_scoped_methods
scoped_methods.last
end