Allinea i KPI su due righe e aggiunge lo storico orario degli invii confermati.
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / scan_ruby (push) Has been cancelled

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-07 12:53:38 +02:00
co-authored by Cursor
parent 390cb0e657
commit 1c6b4bbabe
4 changed files with 61 additions and 1 deletions
@@ -1,6 +1,7 @@
class Mailings::HourlyThroughput
HOUR = 1.hour
RECENT = 15.minutes
HISTORY_HOURS = 12
def initialize(project, now: Time.current)
@project = project
@@ -23,6 +24,31 @@ class Mailings::HourlyThroughput
sent + failed
end
def hourly_history
@hourly_history ||= begin
from = (@now - (HISTORY_HOURS - 1).hours).beginning_of_hour
keyed = recipients.sent
.where(sent_at: from..@now)
.pluck(:sent_at)
.each_with_object(Hash.new(0)) do |sent_at, counts|
counts[sent_at.in_time_zone.beginning_of_hour] += 1
end
HISTORY_HOURS.times.map do |index|
at = from + index.hours
{ at: at, count: keyed[at] || 0 }
end
end
end
def history_total
hourly_history.sum { |bucket| bucket[:count] }
end
def history_max
[hourly_history.map { |bucket| bucket[:count] }.max, 1].max
end
private
def sent_since(window)