fix: ensure loaded survey item responses are uniq by id to avoid PG::CardinalityViolation: ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time (PG::CardinalityViolation)

main-eol
rebuilt 5 months ago
parent 1da1b238e0
commit a3082037fa

@ -43,7 +43,11 @@ class SurveyResponsesDataLoader
row_count += 1
next unless row_count == batch_size
SurveyItemResponse.import(survey_item_responses.compact.flatten, batch_size:, on_duplicate_key_update: :all)
survey_item_responses = survey_item_responses.compact.flatten.uniq do |response|
response.response_id
end
SurveyItemResponse.import(survey_item_responses, batch_size:, on_duplicate_key_update: :all)
survey_item_responses = [] unless file.eof?
GC.start
row_count = 0

Loading…
Cancel
Save