Skip to content

Commit

Permalink
Reapply "PEOPLE: Duplicate Finder Memory Usage (#2824)"
Browse files Browse the repository at this point in the history
This reverts commit 89cd893.
  • Loading branch information
amaierhofer committed Nov 20, 2024
1 parent 52bd097 commit 3ca3456
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gemfile.lock

# reports
spec/coverage
coverage
spec/reports
brakeman-output.tabs
rubocop-results.xml
18 changes: 10 additions & 8 deletions app/domain/insieme/import/person_duplicate_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ca3456

Please sign in to comment.