discourse/app/models/concerns/reports/time_to_first_response.rb
Alan Guo Xiang Tan 0ae7b43018
PERF: Remove total for time to first response report. (#17082)
The query is very inefficient without any constraints on large sites and
the average of all time to first response since the beginning of time is
not useful as well.
2022-06-14 13:27:48 +10:00

24 lines
872 B
Ruby

# frozen_string_literal: true
module Reports::TimeToFirstResponse
extend ActiveSupport::Concern
class_methods do
def report_time_to_first_response(report)
category_filter = report.filters.dig(:category)
category_id, include_subcategories = report.add_category_filter
report.icon = 'reply'
report.higher_is_better = false
report.data = []
report.average = true
Topic.time_to_first_response_per_day(report.start_date, report.end_date, category_id: category_id, include_subcategories: include_subcategories).each do |r|
report.data << { x: r['date'], y: r['hours'].to_f.round(2) }
end
report.prev30Days = Topic.time_to_first_response_total(start_date: report.start_date - 30.days, end_date: report.start_date, category_id: category_id, include_subcategories: include_subcategories)
end
end
end