debian-mirror-gitlab/lib/gitlab/usage/time_frame.rb

31 lines
898 B
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
module Gitlab
module Usage
module TimeFrame
ALL_TIME_TIME_FRAME_NAME = "all"
SEVEN_DAYS_TIME_FRAME_NAME = "7d"
TWENTY_EIGHT_DAYS_TIME_FRAME_NAME = "28d"
2022-08-27 11:52:29 +05:30
DEFAULT_TIMESTAMP_COLUMN = :created_at
2021-09-04 01:27:46 +05:30
def weekly_time_range
{ start_date: 7.days.ago.to_date, end_date: Date.current }
end
def monthly_time_range
{ start_date: 4.weeks.ago.to_date, end_date: Date.current }
end
# This time range is skewed for batch counter performance.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/42972
2022-08-27 11:52:29 +05:30
def monthly_time_range_db_params(column: nil)
{ (column || DEFAULT_TIMESTAMP_COLUMN) => 30.days.ago..2.days.ago }
2021-09-04 01:27:46 +05:30
end
2023-03-04 22:38:38 +05:30
def weekly_time_range_db_params(column: nil)
{ (column || DEFAULT_TIMESTAMP_COLUMN) => 9.days.ago..2.days.ago }
end
2021-09-04 01:27:46 +05:30
end
end
end