Class: PeakFlowUtils::ActiveRecordQuery
- Inherits:
-
Object
- Object
- PeakFlowUtils::ActiveRecordQuery
- Defined in:
- app/services/peak_flow_utils/active_record_query.rb
Defined Under Namespace
Classes: SlowSQLError
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
- #duration_seconds ⇒ Object
-
#initialize(event) ⇒ ActiveRecordQuery
constructor
A new instance of ActiveRecordQuery.
- #perform ⇒ Object
- #report_slow_sql ⇒ Object
- #sql ⇒ Object
- #sql_as_single_line ⇒ Object
Constructor Details
#initialize(event) ⇒ ActiveRecordQuery
Returns a new instance of ActiveRecordQuery.
6 7 8 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 6 def initialize(event) @event = event end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
4 5 6 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 4 def event @event end |
Instance Method Details
#duration_seconds ⇒ Object
14 15 16 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 14 def duration_seconds @duration_seconds ||= event.duration / 1000 end |
#perform ⇒ Object
10 11 12 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 10 def perform report_slow_sql if duration_seconds >= 3 end |
#report_slow_sql ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 18 def report_slow_sql PeakFlowUtils::Notifier.with_parameters(sql: sql, duration_seconds: duration_seconds) do raise SlowSQLError, "Slow SQL: #{sql_as_single_line}" rescue StandardError => e PeakFlowUtils::Notifier.notify(error: e) end end |
#sql ⇒ Object
26 27 28 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 26 def sql @sql ||= event.payload.fetch(:sql) end |
#sql_as_single_line ⇒ Object
30 31 32 |
# File 'app/services/peak_flow_utils/active_record_query.rb', line 30 def sql_as_single_line @sql_as_single_line ||= sql.tr("\n", " ") end |