Skip to content

Commit

Permalink
CV2-5051: exclude logs related to add/remove fact-checks whem migrate…
Browse files Browse the repository at this point in the history
… fact-check logs
  • Loading branch information
melsawy committed Aug 15, 2024
1 parent 7e5bb23 commit 28438aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions app/models/claim_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,19 @@ def replace_media
end

def migrate_claim_and_fact_check_logs
Version.from_partition(self.team_id).where(item_type: 'ClaimDescription', item_id: self.id).update_all(associated_id: self.project_media_id)
# Migrate ClaimDescription logs
cd_versions = Version.from_partition(self.team_id).where(item_type: 'ClaimDescription', item_id: self.id)
# Exclude the one related to add/remove based on object_changes field.
cd_versions = cd_versions.reject do |v|
oc = begin JSON.parse(v.object_changes) rescue {} end
oc.length == 1 && oc.keys.include?('project_media_id')
end
Version.from_partition(self.team_id).where(id: cd_versions.map(&:id)).update_all(associated_id: self.project_media_id)
fc_id = self.fact_check&.id
unless fc_id.nil?
Version.from_partition(self.team_id).where(item_type: 'FactCheck', item_id: fc_id).update_all(associated_id: self.project_media_id)
# Migrate FactCheck logs and exclude create event
Version.from_partition(self.team_id).where(item_type: 'FactCheck', item_id: fc_id)
.where.not(event: 'create').update_all(associated_id: self.project_media_id)
end
end
end
4 changes: 2 additions & 2 deletions test/models/claim_description_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def setup
assert_equal 2, fc.versions.count
# Old item logs
v_count = Version.from_partition(t.id).where(associated_type: 'ProjectMedia', associated_id: pm.id, item_type: ['ClaimDescription', 'FactCheck']).count
assert_equal 0, v_count
assert_equal 2, v_count
# New item logs
v_count = Version.from_partition(t.id).where(associated_type: 'ProjectMedia', associated_id: pm2.id, item_type: ['ClaimDescription', 'FactCheck']).count
assert_equal 6, v_count
assert_equal 4, v_count
end
end
end
Expand Down

0 comments on commit 28438aa

Please sign in to comment.