1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #37328 from eugeneius/sql_active_record_query_cache

Include connection in cached query notifications
This commit is contained in:
Ryuta Kamizono 2019-10-01 17:20:52 +09:00 committed by GitHub
commit eaff375de4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -134,6 +134,7 @@ module ActiveRecord
type_casted_binds: -> { type_casted_binds(binds) },
name: name,
connection_id: object_id,
connection: self,
cached: true
}
end

View file

@ -72,5 +72,30 @@ module ActiveRecord
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def test_payload_connection_with_query_cache_disabled
connection = Book.connection
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
assert_equal connection, event.payload[:connection]
end
Book.first
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def test_payload_connection_with_query_cache_enabled
connection = Book.connection
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
assert_equal connection, event.payload[:connection]
end
Book.cache do
Book.first
Book.first
end
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
end
end