From f146f94ef65ab9c1fa9bc9a509166ed1c1f10477 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 17 Jul 2018 16:47:23 -0400 Subject: [PATCH] FIX: errors when copying post_uploads in discourse_merger.rb --- script/bulk_import/discourse_merger.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/script/bulk_import/discourse_merger.rb b/script/bulk_import/discourse_merger.rb index 0cf9713950c..ae40b36a8ac 100644 --- a/script/bulk_import/discourse_merger.rb +++ b/script/bulk_import/discourse_merger.rb @@ -601,13 +601,11 @@ class BulkImport::DiscourseMerger < BulkImport::Base def process_post_upload(post_upload) return nil unless post_upload['upload_id'].present? - # can't figure out why there are duplicates of these during merge. - # here's a hack to prevent it: @imported_post_uploads ||= {} - return nil if @imported_post_uploads[post_upload['post_id']] == post_upload['upload_id'] - @imported_post_uploads[post_upload['post_id']] = post_upload['upload_id'] + return nil if @imported_post_uploads[post_upload['post_id']]&.include?(post_upload['upload_id']) + @imported_post_uploads[post_upload['post_id']] ||= [] + @imported_post_uploads[post_upload['post_id']] << post_upload['upload_id'] - # ...and there are still duplicates. So try this: return nil if PostUpload.where(post_id: post_upload['post_id'], upload_id: post_upload['upload_id']).exists? post_upload