diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-06 09:09:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-06 09:09:17 +0300 |
commit | 578fc865330cb9ce65746ea5c03e993348e62c96 (patch) | |
tree | 3c8175f1d2192633a17a4a85b0824b07d055c990 /lib/gitlab | |
parent | 23d951df2d16aea96dbd78fd8afe2e22a4794115 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
4 files changed, 32 insertions, 17 deletions
diff --git a/lib/gitlab/background_migration/extract_project_topics_into_separate_table.rb b/lib/gitlab/background_migration/extract_project_topics_into_separate_table.rb index 15ce038321c..c5beb5a6865 100644 --- a/lib/gitlab/background_migration/extract_project_topics_into_separate_table.rb +++ b/lib/gitlab/background_migration/extract_project_topics_into_separate_table.rb @@ -26,12 +26,21 @@ module Gitlab belongs_to :topic end + # Temporary AR table for projects + class Project < ActiveRecord::Base + self.table_name = 'projects' + end + def perform(start_id, stop_id) Tagging.includes(:tag).where(taggable_type: 'Project', id: start_id..stop_id).each do |tagging| - topic = Topic.find_or_create_by(name: tagging.tag.name) - project_topic = ProjectTopic.find_or_create_by(project_id: tagging.taggable_id, topic: topic) - - tagging.delete if project_topic.persisted? + if Project.exists?(id: tagging.taggable_id) + topic = Topic.find_or_create_by(name: tagging.tag.name) + project_topic = ProjectTopic.find_or_create_by(project_id: tagging.taggable_id, topic: topic) + + tagging.delete if project_topic.persisted? + else + tagging.delete + end end mark_job_as_succeeded(start_id, stop_id) diff --git a/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users.rb b/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users.rb index b51fc07f352..7d150b9cd83 100644 --- a/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users.rb +++ b/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users.rb @@ -14,7 +14,7 @@ module Gitlab # The number of rows in merge_request_diff_commits to get in a single # query. - COMMIT_ROWS_PER_QUERY = 10_000 + COMMIT_ROWS_PER_QUERY = 1_000 # The number of rows in merge_request_diff_commits to update in a single # query. diff --git a/lib/gitlab/background_migration/steal_migrate_merge_request_diff_commit_users.rb b/lib/gitlab/background_migration/steal_migrate_merge_request_diff_commit_users.rb index f7eaf01bdc4..43a7032e682 100644 --- a/lib/gitlab/background_migration/steal_migrate_merge_request_diff_commit_users.rb +++ b/lib/gitlab/background_migration/steal_migrate_merge_request_diff_commit_users.rb @@ -15,13 +15,10 @@ module Gitlab end def schedule_next_job - # We process jobs in reverse order, so that (hopefully) we are less - # likely to process jobs that the regular background migration job is - # also processing. next_job = Database::BackgroundMigrationJob .for_migration_class('MigrateMergeRequestDiffCommitUsers') .pending - .last + .first return unless next_job diff --git a/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines.rb b/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines.rb index 1c0dfbdbee3..f637001f9f8 100644 --- a/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines.rb +++ b/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines.rb @@ -7,15 +7,19 @@ module Gitlab class CancelPendingPipelines < Chain::Base include Chain::Helpers + BATCH_SIZE = 25 + + # rubocop: disable CodeReuse/ActiveRecord def perform! return unless project.auto_cancel_pending_pipelines? Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines, name: 'cancel_pending_pipelines') do |cancelables| - cancelables.find_each do |cancelable| - cancelable.auto_cancel_running(pipeline) + cancelables.select(:id).each_batch(of: BATCH_SIZE) do |cancelables_batch| + auto_cancel_interruptible_pipelines(cancelables_batch.ids) end end end + # rubocop: enable CodeReuse/ActiveRecord def break? false @@ -23,16 +27,21 @@ module Gitlab private - # rubocop: disable CodeReuse/ActiveRecord def auto_cancelable_pipelines - project.all_pipelines.ci_and_parent_sources - .where(ref: pipeline.ref) - .where.not(id: pipeline.same_family_pipeline_ids) - .where.not(sha: project.commit(pipeline.ref).try(:id)) + project.all_pipelines.created_after(1.week.ago) + .ci_and_parent_sources + .for_ref(pipeline.ref) + .id_not_in(pipeline.same_family_pipeline_ids) + .where_not_sha(project.commit(pipeline.ref).try(:id)) .alive_or_scheduled + end + + def auto_cancel_interruptible_pipelines(pipeline_ids) + ::Ci::Pipeline + .id_in(pipeline_ids) .with_only_interruptible_builds + .each { |cancelable| cancelable.auto_cancel_running(pipeline) } end - # rubocop: enable CodeReuse/ActiveRecord end end end |