Class: QueriesWatch::Current
- Inherits:
-
ActiveSupport::CurrentAttributes
- Object
- ActiveSupport::CurrentAttributes
- QueriesWatch::Current
- Defined in:
- lib/queries_watch/current.rb
Instance Method Summary collapse
-
#initialize ⇒ Current
constructor
A new instance of Current.
- #level ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize ⇒ Current
Returns a new instance of Current.
9 10 11 12 |
# File 'lib/queries_watch/current.rb', line 9 def initialize super self.logs = [] end |
Instance Method Details
#level ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/queries_watch/current.rb', line 23 def level error_threshold = QueriesWatch.configuration.error_threshold || Float::INFINITY warn_threshold = QueriesWatch.configuration.warn_threshold || Float::INFINITY case logs.count { |log| !log[:cached] } when error_threshold..Float::INFINITY :error when warn_threshold..Float::INFINITY :warn else :info end end |
#summary ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/queries_watch/current.rb', line 14 def summary total_count = logs.size cached_count = logs.count { |log| log[:cached] } exec_count = total_count - cached_count total_duration = '%.1fms' % logs.sum { |log| log[:duration] } OpenStruct.new({ total_count: total_count, cached_count: cached_count, exec_count: exec_count, total_duration: total_duration }).freeze end |