Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix query cache to load before first request #33856

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions activerecord/lib/active_record/railtie.rb
Expand Up @@ -180,9 +180,7 @@ class Railtie < Rails::Railtie # :nodoc:
end

initializer "active_record.set_executor_hooks" do
ActiveSupport.on_load(:active_record) do
ActiveRecord::QueryCache.install_executor_hooks
end
ActiveRecord::QueryCache.install_executor_hooks
end

initializer "active_record.add_watchable_files" do |app|
Expand Down
33 changes: 33 additions & 0 deletions railties/test/application/loading_test.rb
Expand Up @@ -371,6 +371,39 @@ def test_initialize_can_be_called_at_any_time
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!
Expand Down