From 3ca34568f67d45b77c7181249eda5646e7067272 Mon Sep 17 00:00:00 2001 From: Andreas Maierhofer Date: Wed, 20 Nov 2024 10:39:10 +0100 Subject: [PATCH] Reapply "PEOPLE: Duplicate Finder Memory Usage (#2824)" This reverts commit 89cd893f1ecf04f198b32dc1a3461a161b873d7f. --- .gitignore | 1 + .../insieme/import/person_duplicate_finder.rb | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b646284b..ea505e36 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ Gemfile.lock # reports spec/coverage +coverage spec/reports brakeman-output.tabs rubocop-results.xml diff --git a/app/domain/insieme/import/person_duplicate_finder.rb b/app/domain/insieme/import/person_duplicate_finder.rb index e4d0bb41..d009ed3f 100644 --- a/app/domain/insieme/import/person_duplicate_finder.rb +++ b/app/domain/insieme/import/person_duplicate_finder.rb @@ -10,23 +10,25 @@ module Import module PersonDuplicateFinder private - def duplicates(attrs) + def duplicate_ids_with_first_person(attrs) if attrs[:number].present? - ::Person.where(number: attrs[:number]).to_a.presence || - check_duplicate_with_different_number(attrs, super) + people_ids = ::Person.where(number: attrs[:number]).pluck(:id).presence + return {people_ids:, first_person: find_first_person(people_ids)} if people_ids + check_duplicate_with_different_number(attrs, super) else super end end - def check_duplicate_with_different_number(attrs, duplicates) - if duplicates.present? - person = duplicates.first - add_duplicate_with_different_number_error(person) if person.number? + def check_duplicate_with_different_number(attrs, duplicate_ids_with_first_person) + duplicate_ids = duplicate_ids_with_first_person[:people_ids] + first_person = duplicate_ids_with_first_person[:first_person] + if duplicate_ids.present? + add_duplicate_with_different_number_error(first_person) if first_person.number? else attrs[:manual_number] = true end - duplicates + duplicate_ids_with_first_person end def add_duplicate_with_different_number_error(person)