Commit 4689069a authored by Alper Akgun's avatar Alper Akgun Committed by Adam Hegyi

Modify time_period for last 28 days

Aims is to improve batch counting performance
parent 202c6aa0
---
title: Modify time_period for last 28 days to improve batch counting performance
merge_request: 42972
author:
type: performance
...@@ -478,9 +478,10 @@ RSpec.describe Gitlab::UsageData do ...@@ -478,9 +478,10 @@ RSpec.describe Gitlab::UsageData do
end end
describe 'usage_activity_by_stage_secure' do describe 'usage_activity_by_stage_secure' do
let_it_be(:user) { create(:user, group_view: :security_dashboard) } let_it_be(:days_ago_within_monthly_time_period) { 3.days.ago }
let_it_be(:user2) { create(:user, group_view: :security_dashboard) } let_it_be(:user) { create(:user, group_view: :security_dashboard, created_at: days_ago_within_monthly_time_period) }
let_it_be(:user3) { create(:user, group_view: :security_dashboard) } let_it_be(:user2) { create(:user, group_view: :security_dashboard, created_at: days_ago_within_monthly_time_period) }
let_it_be(:user3) { create(:user, group_view: :security_dashboard, created_at: days_ago_within_monthly_time_period) }
before do before do
for_defined_days_back do for_defined_days_back do
......
...@@ -473,7 +473,7 @@ module Gitlab ...@@ -473,7 +473,7 @@ module Gitlab
end end
def last_28_days_time_period(column: :created_at) def last_28_days_time_period(column: :created_at)
{ column => 28.days.ago..Time.current } { column => 30.days.ago..2.days.ago }
end end
# Source: https://gitlab.com/gitlab-data/analytics/blob/master/transform/snowflake-dbt/data/ping_metrics_to_stage_mapping_data.csv # Source: https://gitlab.com/gitlab-data/analytics/blob/master/transform/snowflake-dbt/data/ping_metrics_to_stage_mapping_data.csv
......
...@@ -97,9 +97,9 @@ FactoryBot.define do ...@@ -97,9 +97,9 @@ FactoryBot.define do
create(:grafana_integration, project: projects[1], enabled: true) create(:grafana_integration, project: projects[1], enabled: true)
create(:grafana_integration, project: projects[2], enabled: false) create(:grafana_integration, project: projects[2], enabled: false)
create(:package, project: projects[0]) create(:package, project: projects[0], created_at: 3.days.ago)
create(:package, project: projects[0]) create(:package, project: projects[0], created_at: 3.days.ago)
create(:package, project: projects[1]) create(:package, project: projects[1], created_at: 3.days.ago)
create(:package, created_at: 2.months.ago, project: projects[1]) create(:package, created_at: 2.months.ago, project: projects[1])
# User Preferences # User Preferences
...@@ -109,7 +109,7 @@ FactoryBot.define do ...@@ -109,7 +109,7 @@ FactoryBot.define do
# Create fresh & a month (28-days SMAU) old data # Create fresh & a month (28-days SMAU) old data
env = create(:environment, project: projects[3]) env = create(:environment, project: projects[3])
[2, 29].each do |n| [3, 31].each do |n|
deployment_options = { created_at: n.days.ago, project: env.project, environment: env } deployment_options = { created_at: n.days.ago, project: env.project, environment: env }
create(:deployment, :failed, deployment_options) create(:deployment, :failed, deployment_options)
create(:deployment, :success, deployment_options) create(:deployment, :success, deployment_options)
......
...@@ -1020,7 +1020,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1020,7 +1020,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
def for_defined_days_back(days: [29, 2]) def for_defined_days_back(days: [31, 3])
days.each do |n| days.each do |n|
Timecop.travel(n.days.ago) do Timecop.travel(n.days.ago) do
yield yield
......
...@@ -229,7 +229,7 @@ module UsageDataHelpers ...@@ -229,7 +229,7 @@ module UsageDataHelpers
receive_matchers.each { |m| expect(prometheus_client).to m } receive_matchers.each { |m| expect(prometheus_client).to m }
end end
def for_defined_days_back(days: [29, 2]) def for_defined_days_back(days: [31, 3])
days.each do |n| days.each do |n|
Timecop.travel(n.days.ago) do Timecop.travel(n.days.ago) do
yield yield
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment