Commit 561e00b2 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'query-counting-should-not-include-cached-queries' into 'master'

Do not count rails sql cache as queries in query limiting

See merge request gitlab-org/gitlab-ce!17253
parents 216d21c5 2e216dd4
...@@ -3,8 +3,10 @@ module Gitlab ...@@ -3,8 +3,10 @@ module Gitlab
class ActiveSupportSubscriber < ActiveSupport::Subscriber class ActiveSupportSubscriber < ActiveSupport::Subscriber
attach_to :active_record attach_to :active_record
def sql(*) def sql(event)
Transaction.current&.increment unless event.payload[:name] == 'CACHE'
Transaction.current&.increment
end
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::QueryLimiting::ActiveSupportSubscriber do describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
let(:transaction) { instance_double(Gitlab::QueryLimiting::Transaction, increment: true) }
before do
allow(Gitlab::QueryLimiting::Transaction)
.to receive(:current)
.and_return(transaction)
end
describe '#sql' do describe '#sql' do
it 'increments the number of executed SQL queries' do it 'increments the number of executed SQL queries' do
transaction = double(:transaction) User.count
allow(Gitlab::QueryLimiting::Transaction)
.to receive(:current)
.and_return(transaction)
expect(transaction) expect(transaction)
.to receive(:increment) .to have_received(:increment)
.at_least(:once) .once
end
User.count context 'when the query is actually a rails cache hit' do
it 'does not increment the number of executed SQL queries' do
ActiveRecord::Base.connection.cache do
User.count
User.count
end
expect(transaction)
.to have_received(:increment)
.once
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment