From 327fe2deaf33a15a42433ff192a5de33aaa810a6 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 5c14adc499..591b112127 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 5e09845b53..a77acc0732 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