diff options
4 files changed, 19 insertions, 5 deletions
diff --git a/app/workers/namespaces/prune_aggregation_schedules_worker.rb b/app/workers/namespaces/prune_aggregation_schedules_worker.rb index c660727869e..4e40feee702 100644 --- a/app/workers/namespaces/prune_aggregation_schedules_worker.rb +++ b/app/workers/namespaces/prune_aggregation_schedules_worker.rb @@ -6,9 +6,9 @@ module Namespaces include CronjobQueue # Worker to prune pending rows on Namespace::AggregationSchedule - # It's scheduled to run once a day at midnight. + # It's scheduled to run once a day at 1:05am. def perform - aggregation_schedules.each do |aggregation_schedule| + aggregation_schedules.find_each do |aggregation_schedule| aggregation_schedule.schedule_root_storage_statistics end end diff --git a/app/workers/namespaces/schedule_aggregation_worker.rb b/app/workers/namespaces/schedule_aggregation_worker.rb index 941149459c7..a4594b84b13 100644 --- a/app/workers/namespaces/schedule_aggregation_worker.rb +++ b/app/workers/namespaces/schedule_aggregation_worker.rb @@ -26,8 +26,8 @@ module Namespaces # calls UpdateProjectStatistics#schedule_namespace_statistics_worker. # # The migration and specs fails since NamespaceAggregationSchedule table - # does not exist at that point. Technical debt issue: - # https://gitlab.com/gitlab-org/gitlab-ce/issues/63775 + # does not exist at that point. + # https://gitlab.com/gitlab-org/gitlab-ce/issues/50712 def aggregation_schedules_table_exists? return true unless Rails.env.test? diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 5c9ca97534d..bf187e9a282 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -442,7 +442,7 @@ Settings.cron_jobs['schedule_migrate_external_diffs_worker'] ||= Settingslogic.n Settings.cron_jobs['schedule_migrate_external_diffs_worker']['cron'] ||= '15 * * * *' Settings.cron_jobs['schedule_migrate_external_diffs_worker']['job_class'] = 'ScheduleMigrateExternalDiffsWorker' Settings.cron_jobs['namespaces_prune_aggregation_schedules_worker'] ||= Settingslogic.new({}) -Settings.cron_jobs['namespaces_prune_aggregation_schedules_worker']['cron'] ||= '0 0 * * *' +Settings.cron_jobs['namespaces_prune_aggregation_schedules_worker']['cron'] ||= '5 1 * * *' Settings.cron_jobs['namespaces_prune_aggregation_schedules_worker']['job_class'] = 'Namespaces::PruneAggregationSchedulesWorker' Gitlab.ee do diff --git a/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb index a49d04958e7..aad63982e7a 100644 --- a/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb +++ b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb @@ -74,6 +74,20 @@ shared_examples_for 'UpdateProjectStatistics' do subject.save! end + it 'avoids N + 1 queries' do + subject.write_attribute(statistic_attribute, read_attribute + delta) + + control_count = ActiveRecord::QueryRecorder.new do + subject.save! + end + + subject.write_attribute(statistic_attribute, read_attribute + delta) + + expect do + subject.save! + end.not_to exceed_query_limit(control_count) + end + context 'when the feature flag is disabled for the namespace' do it 'does not schedule a namespace statistics worker' do namespace = subject.project.root_ancestor |