Fix grouped duration_seconds overcounting by using global LAG instead of partitioned LAG (#1075)

This commit is contained in:
Mahad Kalam 2026-03-15 20:22:01 +00:00 committed by GitHub
parent 9858cec9de
commit 972d6d2e33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -223,8 +223,8 @@ module Heartbeatable
capped_diffs = scope
.select("#{group_expr} as grouped_time, CASE
WHEN LAG(time) OVER (PARTITION BY #{group_expr} ORDER BY time) IS NULL THEN 0
ELSE LEAST(time - LAG(time) OVER (PARTITION BY #{group_expr} ORDER BY time), #{timeout})
WHEN LAG(time) OVER (ORDER BY time) IS NULL THEN 0
ELSE LEAST(time - LAG(time) OVER (ORDER BY time), #{timeout})
END as diff")
.where.not(time: nil)
.unscope(:group)