Skip to content

Commit

Permalink
fix logging of cached queries with binds in rails 5.1.5
Browse files Browse the repository at this point in the history
fixes CORE-1082

Change-Id: Ib8c4dd84e47d0e127ad09cab6ed416f5a37abe3d
Reviewed-on: https://gerrit.instructure.com/142668
Reviewed-by: Rob Orton <[email protected]>
Tested-by: Jenkins
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Mar 6, 2018
1 parent e545c26 commit 7d99c14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/switchman/active_record/query_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ def cache_sql(sql, name, binds)
@lock.synchronize do
result =
if query_cache[sql].key?(binds)
args = {
sql: sql,
binds: binds,
name: name,
connection_id: object_id,
cached: true
}
args[:type_casted_binds] = -> { type_casted_binds(binds) } if ::Rails.version >= '5.1.5'
::ActiveSupport::Notifications.instrument(
"sql.active_record",
sql: sql,
binds: binds,
name: name,
connection_id: object_id,
cached: true,
args
)
query_cache[sql][binds]
else
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/active_record/query_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ module ActiveRecord
@shard1.activate { User.connection.expects(:select).never }
expect(@shard1.activate { User.all.to_a }).not_to eq @shard3.activate { User.all.to_a }
end

it "doesn't break logging with binds" do
::Rails.logger.expects(:error).never
User.connection.cache do
User.where(id: 1).take
User.where(id: 1).take
end
end
else
# call with two blocks. the first will run on a new thread, pausing at
# the site of a "cc.call". the second will run on the original thread
Expand Down

0 comments on commit 7d99c14

Please sign in to comment.