Skip to content

Commit

Permalink
Only Group Duplicates when new publication during AI import (#583)
Browse files Browse the repository at this point in the history
* Tweaks to ai importer to only group duplicates when a new publication is created and tweaked the duplicate grouping task to toggle publications to not be visible if they have not already been grouped.

* Niftany
  • Loading branch information
ajkiessl authored Oct 24, 2022
1 parent 1eff6a6 commit a0e868f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
11 changes: 5 additions & 6 deletions app/importers/activity_insight_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def call
update_pub_record(pub_record, pub)
else
pi.save!

DuplicatePublicationGroup.group_duplicates_of(pub_record)
if pub_record.reload.duplicate_group
pub_record.update!(visible: false)
end
end

if pub_record.updated_by_user_at.blank?
Expand Down Expand Up @@ -195,12 +200,6 @@ def call
c.save!
end
end

DuplicatePublicationGroup.group_duplicates_of(pub_record)

if pub_record.reload.duplicate_group
pub_record.update!(visible: false)
end
end
rescue StandardError => e
log_error(pub, e, u)
Expand Down
5 changes: 5 additions & 0 deletions app/models/duplicate_publication_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ def self.group_duplicates
total: Publication.count)

Publication.find_each do |p|
already_grouped = p.duplicate_group.present?
group_duplicates_of(p)

group = p.reload.duplicate_group
if !already_grouped && group
p.update!(visible: false)
end
pbar.increment
end
pbar.finish
Expand Down
4 changes: 2 additions & 2 deletions spec/component/importers/activity_insight_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@
end

it 'groups duplicates of new publication records' do
expect { importer.call }.to change(DuplicatePublicationGroup, :count).by 2
expect { importer.call }.to change(DuplicatePublicationGroup, :count).by 1

p1 = PublicationImport.find_by(source: 'Activity Insight',
source_identifier: '190706413568').publication
Expand Down Expand Up @@ -1465,7 +1465,7 @@
end

it 'groups duplicates of new publication records' do
expect { importer.call }.to change(DuplicatePublicationGroup, :count).by 2
expect { importer.call }.to change(DuplicatePublicationGroup, :count).by 1

p1 = PublicationImport.find_by(source: 'Activity Insight',
source_identifier: '190706413568').publication
Expand Down
34 changes: 34 additions & 0 deletions spec/component/models/duplicate_publication_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,40 @@
expect(p15_1.reload.duplicate_group.publications).to match_array [p15_1, p15_2]
expect(p16_1.reload.duplicate_group.publications).to match_array [p16_1, p16_2]
end

it "sets grouped publications' visible statuses to false when publication was not already grouped before process started" do
described_class.group_duplicates

expect(p1_1.reload.duplicate_group.publications.map(&:visible)).to match_array [true, false, false, false]
expect(p2_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p3_1.reload.visible).to be true
expect(p3_2.reload.visible).to be true
expect(p4_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p5_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p6_1.reload.visible).to be true
expect(p6_2.reload.visible).to be true
expect(p7_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p8_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p9_1.reload.visible).to be true
expect(p9_2.reload.visible).to be true
expect(p10_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p11_1.reload.visible).to be true
expect(p11_2.reload.visible).to be true
expect(p11_3.reload.visible).to be true
expect(p12_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false]
expect(p12_2.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false]
expect(p12_3.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false]
expect(p13_1.reload.visible).to be true
expect(p13_2.reload.visible).to be true
expect(p14_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false, false]
expect(p14_2.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false, false]
expect(p14_3.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false, false]
expect(p14_4.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false, false, false]
expect(p15_1.reload.duplicate_group.publications.map(&:visible)).to match_array [false, false]
expect(p16_1.reload.duplicate_group.publications.map(&:visible)).to match_array [true, false]
expect(p17_1.reload.visible).to be true
expect(p17_2.reload.visible).to be true
end
end
end

Expand Down

0 comments on commit a0e868f

Please sign in to comment.