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

Include connection in cached query notifications

Since 6d1c9a9b23 the `sql.active_record`
notification includes the connection that executed the query, but only
when the result comes from the database, not the query cache.
This commit is contained in:
Eugene Kenny 2019-10-01 00:35:32 +01:00
parent 4f5c63296e
commit cb7c92203b
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