Class: QueryGuard::Analyzers::QueryCountAnalyzer
- Defined in:
- lib/query_guard/analyzers/query_count_analyzer.rb
Overview
Detects when query count per request exceeds threshold.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #analyze(context, config) ⇒ Object
-
#initialize ⇒ QueryCountAnalyzer
constructor
A new instance of QueryCountAnalyzer.
Methods inherited from Base
Constructor Details
#initialize ⇒ QueryCountAnalyzer
Returns a new instance of QueryCountAnalyzer.
7 8 9 |
# File 'lib/query_guard/analyzers/query_count_analyzer.rb', line 7 def initialize super(:query_count) end |
Instance Method Details
#analyze(context, config) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/query_guard/analyzers/query_count_analyzer.rb', line 11 def analyze(context, config) findings = [] limit = config.max_queries_per_request return findings if limit.nil? count = context.queries.length return findings unless count > limit findings << Core::FindingBuilders.too_many_queries( count: count, limit: limit, total_duration_ms: context.total_duration_ms, severity: config.query_count_severity || :warn ) findings end |