diff options
author | Eugene Kenny <elkenny@gmail.com> | 2015-04-29 11:02:47 +0100 |
---|---|---|
committer | Eugene Kenny <elkenny@gmail.com> | 2015-04-29 11:02:47 +0100 |
commit | 33fe7cc8892e7e2cf82f7cb0baf467590eb61988 (patch) | |
tree | c89048ab57537411aa93b749b7985f372d0b321b /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | |
parent | 4e6f0053db49f8c5b207c739efc39dd86c2552e3 (diff) | |
download | rails-33fe7cc8892e7e2cf82f7cb0baf467590eb61988.tar.gz rails-33fe7cc8892e7e2cf82f7cb0baf467590eb61988.tar.bz2 rails-33fe7cc8892e7e2cf82f7cb0baf467590eb61988.zip |
Apply schema cache dump when creating connections
The `db:schema:cache:dump` rake task dumps the database schema structure
to `db/schema_cache.dump`. If this file is present, the schema details
are loaded into the currently checked out connection by a railtie while
Rails is booting, to avoid having to query the database for its schema.
The schema cache dump is only applied to the initial connection used to
boot the application though; other connections from the same pool are
created with an empty schema cache, and still have to load the structure
of each table directly from the database.
With this change, a copy of the schema cache is associated with the
connection pool and applied to connections as they are created.
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.rb | 6 |
1 files changed, 4 insertions, 2 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 8c50f3d1a3..77e64a22be 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -220,7 +220,7 @@ module ActiveRecord include MonitorMixin - attr_accessor :automatic_reconnect, :checkout_timeout + attr_accessor :automatic_reconnect, :checkout_timeout, :schema_cache attr_reader :spec, :connections, :size, :reaper # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification @@ -432,7 +432,9 @@ module ActiveRecord end def new_connection - Base.send(spec.adapter_method, spec.config) + Base.send(spec.adapter_method, spec.config).tap do |conn| + conn.schema_cache = schema_cache.dup if schema_cache + end end def current_connection_id #:nodoc: |