mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Load db/schema_cache.dump duaring boot time.
This commit is contained in:
parent
0150a212c0
commit
0da12df260
5 changed files with 32 additions and 3 deletions
|
@ -86,6 +86,11 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def schema_cache=(cache)
|
||||
cache.connection = self
|
||||
@schema_cache = cache
|
||||
end
|
||||
|
||||
def expire
|
||||
@in_use = false
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ module ActiveRecord
|
|||
module ConnectionAdapters
|
||||
class SchemaCache
|
||||
attr_reader :columns, :columns_hash, :primary_keys, :tables
|
||||
attr_reader :connection
|
||||
attr_accessor :connection
|
||||
|
||||
def initialize(conn)
|
||||
@connection = conn
|
||||
|
|
|
@ -107,7 +107,7 @@ module ActiveRecord
|
|||
config.watchable_files.concat ["#{app.root}/db/schema.rb", "#{app.root}/db/structure.sql"]
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
config.after_initialize do |app|
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
ActiveRecord::Base.instantiate_observers
|
||||
|
||||
|
@ -115,6 +115,17 @@ module ActiveRecord
|
|||
ActiveRecord::Base.instantiate_observers
|
||||
end
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
if app.config.use_schema_cache_dump
|
||||
filename = File.join(app.config.paths["db"].first, "schema_cache.dump")
|
||||
if File.file?(filename)
|
||||
cache = Marshal.load(open(filename, 'rb') { |f| f.read })
|
||||
ActiveRecord::Base.connection.schema_cache = cache
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module Rails
|
|||
:force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks,
|
||||
:railties_order, :relative_url_root, :secret_token,
|
||||
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
|
||||
:time_zone, :reload_classes_only_on_change
|
||||
:time_zone, :reload_classes_only_on_change, :use_schema_cache_dump
|
||||
|
||||
attr_writer :log_level
|
||||
attr_reader :encoding
|
||||
|
@ -41,6 +41,7 @@ module Rails
|
|||
@file_watcher = ActiveSupport::FileUpdateChecker
|
||||
@exceptions_app = nil
|
||||
@autoflush_log = true
|
||||
@use_schema_cache_dump = true
|
||||
|
||||
@assets = ActiveSupport::OrderedOptions.new
|
||||
@assets.enabled = false
|
||||
|
|
|
@ -193,5 +193,17 @@ module ApplicationTests
|
|||
require "#{app_path}/config/environment"
|
||||
assert_nil defined?(ActiveRecord::Base)
|
||||
end
|
||||
|
||||
test "use schema cache dump" do
|
||||
Dir.chdir(app_path) do
|
||||
`rails generate model post title:string`
|
||||
`bundle exec rake db:migrate`
|
||||
`bundle exec rake db:schema:cache:dump`
|
||||
end
|
||||
require "#{app_path}/config/environment"
|
||||
ActiveRecord::Base.connection.drop_table("posts") # force drop posts table for test.
|
||||
assert ActiveRecord::Base.connection.schema_cache.tables["posts"]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue