Fix list import concurrently creating lists of the same name (#26372)

pull/2363/head
Claire 2023-08-07 17:59:20 +02:00 committed by GitHub
parent cd6f2b3cbc
commit 30c64bf616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -162,10 +162,9 @@ class BulkImportService < BaseService
def import_lists!
rows = @import.rows.to_a
included_lists = rows.map { |row| row.data['list_name'] }.uniq
if @import.overwrite?
included_lists = rows.map { |row| row.data['list_name'] }.uniq
@account.owned_lists.where.not(title: included_lists).destroy_all
# As list membership changes do not retroactively change timeline
@ -175,6 +174,10 @@ class BulkImportService < BaseService
end
end
included_lists.each do |title|
@account.owned_lists.find_or_create_by!(title: title)
end
Import::RowWorker.push_bulk(rows) do |row|
[row.id]
end

View File

@ -161,6 +161,12 @@ RSpec.describe BulkImportRowService do
end
include_examples 'common behavior'
it 'does not create a new list' do
account.follow!(target_account)
expect { subject.call(import_row) }.to_not(change { List.where(title: 'my list').count })
end
end
end
end