Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Load db/schema_cache.dump duaring boot time.

  • Loading branch information...
commit 0da12df2608969330bd47c543866f79ff8ca9edd 1 parent 0150a21
@kennyj kennyj authored
View
5 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -86,6 +86,11 @@ def lease
end
end
+ def schema_cache=(cache)
+ cache.connection = self
+ @schema_cache = cache
+ end
+
def expire
@in_use = false
end
View
2  activerecord/lib/active_record/connection_adapters/schema_cache.rb
@@ -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
View
13 activerecord/lib/active_record/railtie.rb
@@ -107,7 +107,7 @@ class Railtie < Rails::Railtie
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 @@ class Railtie < Rails::Railtie
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
View
3  railties/lib/rails/application/configuration.rb
@@ -11,7 +11,7 @@ class Configuration < ::Rails::Engine::Configuration
: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
@josevalim Owner

This configuration should not be here. It is specific to Active Record and therefore should be defined in Active Record railtie.

@kennyj Collaborator
kennyj added a note

Certainly, I agree with you.. Do you mean kennyj@82bd05a ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
attr_writer :log_level
attr_reader :encoding
@@ -41,6 +41,7 @@ def initialize(*)
@file_watcher = ActiveSupport::FileUpdateChecker
@exceptions_app = nil
@autoflush_log = true
+ @use_schema_cache_dump = true
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
View
12 railties/test/application/initializers/frameworks_test.rb
@@ -193,5 +193,17 @@ def from_bar_helper
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
@josevalim

This configuration should not be here. It is specific to Active Record and therefore should be defined in Active Record railtie.

@kennyj

Certainly, I agree with you.. Do you mean kennyj@82bd05a ?

Please sign in to comment.
Something went wrong with that request. Please try again.