Update PageViewRollup (#20785)

* Make sure time is beginning of day

* Use correct initial time
This commit is contained in:
Mac Siri 2024-03-21 18:37:33 -04:00 committed by GitHub
parent b0cc94e655
commit 7988af1628
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,7 +41,7 @@ class PageViewRollup
end
def self.rollup(date, relation: PageView)
new(relation: relation).rollup(date.to_datetime)
new(relation: relation).rollup(date)
end
def initialize(relation:)
@ -52,10 +52,11 @@ class PageViewRollup
def rollup(date)
created = []
fixed_date = date.to_datetime.beginning_of_day
(0..23).each do |hour|
start_hour = date.change(hour: hour)
end_hour = date.change(hour: hour + 1)
start_hour = fixed_date.change(hour: hour)
end_hour = fixed_date.change(hour: hour + 1)
rows = relation.where(user_id: nil, created_at: start_hour...end_hour)
aggregate_into_groups(rows).each do |compacted_views|
created << compact_records(start_hour, compacted_views)