aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorEileen Uchitelle <eileencodes@gmail.com>2018-09-12 10:09:59 -0400
committerEileen Uchitelle <eileencodes@gmail.com>2018-09-12 10:09:59 -0400
commit349db176d8283a5c16816b50a92b0b319b1b8b74 (patch)
treef80a85ef9868212d9ad3b243f9233a7ebecb9e9d /railties
parent3eb0406ef56dab8c8cd60378600a53e351de0053 (diff)
downloadrails-349db176d8283a5c16816b50a92b0b319b1b8b74.tar.gz
rails-349db176d8283a5c16816b50a92b0b319b1b8b74.tar.bz2
rails-349db176d8283a5c16816b50a92b0b319b1b8b74.zip
Fix query cache to load before first request
In a test app we observed that the query cache was not enabled on the first request. This was because the query cache hooks are installed on load and active record is loaded in the middle of the first request. If we remove the `on_load` from the railtie the query cache hooks will be installed before the first request, allowing the cache to be enabled on that first request. This is ok because query cache doesn't load anything else, only itself so we're not eager loading all of active record before the first request, just the query cache hooks. [Eileen M. Uchitelle & Matthew Draper]
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/loading_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index 889ad16fb8..d7f4f09665 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -371,6 +371,39 @@ class LoadingTest < ActiveSupport::TestCase
end
end
+ test "active record query cache hooks are installed before first request" do
+ app_file "app/controllers/omg_controller.rb", <<-RUBY
+ begin
+ class OmgController < ActionController::Metal
+ ActiveSupport.run_load_hooks(:action_controller, self)
+ def show
+ if ActiveRecord::Base.connection.query_cache_enabled
+ self.response_body = ["Query cache is enabled."]
+ else
+ self.response_body = ["Expected ActiveRecord::Base.connection.query_cache_enabled to be true"]
+ end
+ end
+ end
+ rescue => e
+ puts "Error loading metal: \#{e.class} \#{e.message}"
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ get "/:controller(/:action)"
+ end
+ RUBY
+
+ require "#{rails_root}/config/environment"
+
+ require "rack/test"
+ extend Rack::Test::Methods
+
+ get "/omg/show"
+ assert_equal "Query cache is enabled.", last_response.body
+ end
+
private
def setup_ar!