Handle uniqueness on fork_network_member creation
Since the migration might be queued already and be rescheduled when it fails on a uniqueness error, this should help clearing the background migration queue faster.
This commit is contained in:
parent
7e00adcc71
commit
0478ff7cd4
1 changed files with 11 additions and 4 deletions
|
@ -14,6 +14,14 @@ module Gitlab
|
|||
def perform(start_id, end_id)
|
||||
log("Creating memberships for forks: #{start_id} - #{end_id}")
|
||||
|
||||
insert_members(start_id, end_id)
|
||||
|
||||
if missing_members?(start_id, end_id)
|
||||
BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, "CreateForkNetworkMembershipsRange", [start_id, end_id])
|
||||
end
|
||||
end
|
||||
|
||||
def insert_members(start_id, end_id)
|
||||
ActiveRecord::Base.connection.execute <<~INSERT_MEMBERS
|
||||
INSERT INTO fork_network_members (fork_network_id, project_id, forked_from_project_id)
|
||||
|
||||
|
@ -33,10 +41,9 @@ module Gitlab
|
|||
WHERE existing_members.project_id = forked_project_links.forked_to_project_id
|
||||
)
|
||||
INSERT_MEMBERS
|
||||
|
||||
if missing_members?(start_id, end_id)
|
||||
BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, "CreateForkNetworkMembershipsRange", [start_id, end_id])
|
||||
end
|
||||
rescue ActiveRecord::RecordNotUnique => e
|
||||
# `fork_network_member` was created concurrently in another migration
|
||||
log(e.message)
|
||||
end
|
||||
|
||||
def missing_members?(start_id, end_id)
|
||||
|
|
Loading…
Reference in a new issue