From 30c64bf61676f8fcccc17b253a0a58cd6f51fc69 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 7 Aug 2023 17:59:20 +0200 Subject: [PATCH] Fix list import concurrently creating lists of the same name (#26372) --- app/services/bulk_import_service.rb | 7 +++++-- spec/services/bulk_import_row_service_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_import_service.rb b/app/services/bulk_import_service.rb index 5c14adc49..591b11212 100644 --- a/app/services/bulk_import_service.rb +++ b/app/services/bulk_import_service.rb @@ -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 diff --git a/spec/services/bulk_import_row_service_spec.rb b/spec/services/bulk_import_row_service_spec.rb index 5e09845b5..a77acc073 100644 --- a/spec/services/bulk_import_row_service_spec.rb +++ b/spec/services/bulk_import_row_service_spec.rb @@ -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