From 58b3d523890d0580fce90ef789d11c4e5abc09fe Mon Sep 17 00:00:00 2001 From: satikaj <117552851+satikaj@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:55:21 +1000 Subject: [PATCH] refactor: optimise task comment update --- ...20240601103707_add_polymorphic_association_to_comment.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/db/migrate/20240601103707_add_polymorphic_association_to_comment.rb b/db/migrate/20240601103707_add_polymorphic_association_to_comment.rb index bea8d90ab..f6828c0b2 100644 --- a/db/migrate/20240601103707_add_polymorphic_association_to_comment.rb +++ b/db/migrate/20240601103707_add_polymorphic_association_to_comment.rb @@ -5,11 +5,7 @@ def change add_column :task_comments, :commentable_type, :string rename_column :task_comments, :overseer_assessment_id, :commentable_id - TaskComment.find_each do |comment| - if comment.commentable_id.present? - comment.update(commentable_type: 'OverseerAssessment') - end - end + TaskComment.where('NOT commentable_id IS NULL').in_batches.update_all(commentable_type: 'OverseerAssessment') add_index :task_comments, [:commentable_type, :commentable_id] end