FIX: errors when copying post_uploads in discourse_merger.rb

This commit is contained in:
Neil Lalonde 2018-07-17 16:47:23 -04:00
parent 04077a7df6
commit f146f94ef6
1 changed files with 3 additions and 5 deletions

View File

@ -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