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:
commit
eaff375de4
2 changed files with 26 additions and 0 deletions
|
@ -134,6 +134,7 @@ module ActiveRecord
|
|||
type_casted_binds: -> { type_casted_binds(binds) },
|
||||
name: name,
|
||||
connection_id: object_id,
|
||||
connection: self,
|
||||
cached: true
|
||||
}
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue