Commit 32dc1beb authored by nmilojevic1's avatar nmilojevic1

Simplify logic for showing cached count in performance bar

parent 735db8b7
...@@ -5,7 +5,6 @@ module Peek ...@@ -5,7 +5,6 @@ module Peek
class ActiveRecord < DetailedView class ActiveRecord < DetailedView
DEFAULT_THRESHOLDS = { DEFAULT_THRESHOLDS = {
calls: 100, calls: 100,
cached_calls: 100,
duration: 3000, duration: 3000,
individual_call: 1000 individual_call: 1000
}.freeze }.freeze
...@@ -13,7 +12,6 @@ module Peek ...@@ -13,7 +12,6 @@ module Peek
THRESHOLDS = { THRESHOLDS = {
production: { production: {
calls: 100, calls: 100,
cached_calls: 100,
duration: 15000, duration: 15000,
individual_call: 5000 individual_call: 5000
} }
...@@ -30,25 +28,13 @@ module Peek ...@@ -30,25 +28,13 @@ module Peek
private private
def detailed_calls def detailed_calls
cached_calls? ? "#{calls} | #{cached_calls}" : calls "#{calls} (#{cached_calls} cached)"
end
def calls
super - cached_calls
end end
def cached_calls def cached_calls
detail_store.count { |item| item[:cached] == 'cached' } detail_store.count { |item| item[:cached] == 'cached' }
end end
def cached_calls?
detail_store.any? { |item| item[:cached] == 'cached' }
end
def warnings
(super + warning_for(cached_calls, self.class.thresholds[:cached_calls], label: "#{key} cached calls")).compact
end
def setup_subscribers def setup_subscribers
super super
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Peek::Views::ActiveRecord, :request_store do
context 'when a class defines thresholds' do
let(:threshold_view) do
Class.new(described_class) do
def self.thresholds
{
calls: 1,
cached_calls: 1,
duration: 10,
individual_call: 5
}
end
def key
'threshold-view'
end
end.new
end
context 'when the results exceed the cached calls threshold' do
before do
allow(threshold_view)
.to receive(:detail_store).and_return([{ duration: 0.001, cached: 'cached' }, { duration: 0.001, cached: 'cached' }])
end
it 'adds a warning to the results key' do
expect(threshold_view.results).to include(warnings: [a_string_matching('threshold-view cached calls')])
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