aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2015-05-17 00:57:52 +0100
committerEugene Kenny <elkenny@gmail.com>2015-05-17 00:57:52 +0100
commit19bc570832e01c47f42ac2096637df59613c0efa (patch)
tree03b1b751f3fde2107c42fd21c17b36d6aa5c41ed /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parent50999974e80ee9ddf3d81c3b9733f84f5646705c (diff)
downloadrails-19bc570832e01c47f42ac2096637df59613c0efa.tar.gz
rails-19bc570832e01c47f42ac2096637df59613c0efa.tar.bz2
rails-19bc570832e01c47f42ac2096637df59613c0efa.zip
Add schema cache to new connection pool after fork
Active Record detects when the process has forked and automatically creates a new connection pool to avoid sharing file descriptors. If the existing connection pool had a schema cache associated with it, the new pool should copy it to avoid unnecessarily querying the database for its schema. The code to detect that the process has forked is in ConnectionHandler, but the existing test for it was in the ConnectionManagement test file. I moved it to the right place while I was writing the new test for this change.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 5bfb4d779c..6535121075 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -933,7 +933,9 @@ module ActiveRecord
# A connection was established in an ancestor process that must have
# subsequently forked. We can't reuse the connection, but we can copy
# the specification and establish a new connection with it.
- establish_connection owner, ancestor_pool.spec
+ establish_connection(owner, ancestor_pool.spec).tap do |pool|
+ pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
+ end
else
owner_to_pool[owner.name] = nil
end