From 6ffd37f5054cc46e92fa5fff0ebbbac5f821fe8d Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Thu, 4 Feb 2021 14:27:15 -0600 Subject: [PATCH] Reduced migration batch size to reduce memory pressure --- ...2184008_copy_attachments_to_active_storage.rb | 2 +- ...937_replace_type_tags_with_assignment_type.rb | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/db/migrate/20210202184008_copy_attachments_to_active_storage.rb b/db/migrate/20210202184008_copy_attachments_to_active_storage.rb index 6c7689b7..a4e06a1f 100644 --- a/db/migrate/20210202184008_copy_attachments_to_active_storage.rb +++ b/db/migrate/20210202184008_copy_attachments_to_active_storage.rb @@ -5,7 +5,7 @@ class CopyAttachmentsToActiveStorage < ActiveRecord::Migration[6.1] disable_ddl_transaction! def up - Exercise.joins(:attachments).preload(:attachments).find_each do |exercise| + Exercise.joins(:attachments).preload(:attachments).find_each(batch_size: 100) do |exercise| next unless exercise.images.empty? exercise.attachments.each do |attachment| diff --git a/db/migrate/20210203154937_replace_type_tags_with_assignment_type.rb b/db/migrate/20210203154937_replace_type_tags_with_assignment_type.rb index 62ce3f70..02001a75 100644 --- a/db/migrate/20210203154937_replace_type_tags_with_assignment_type.rb +++ b/db/migrate/20210203154937_replace_type_tags_with_assignment_type.rb @@ -8,7 +8,8 @@ def up exercise_ids = ExerciseTag.where(tag_id: old_hw_tag_ids).distinct.pluck(:exercise_id) Exercise.where(id: exercise_ids) .latest - .preload(:exercise_tags, :publication).find_each do |exercise| + .preload(:exercise_tags, :publication) + .find_each(batch_size: 100) do |exercise| Exercise.transaction do if exercise.is_published? exercise = exercise.new_version @@ -25,7 +26,8 @@ def up vocab_term_ids = VocabTermTag.where(tag_id: old_hw_tag_ids).distinct.pluck(:vocab_term_id) VocabTerm.where(id: vocab_term_ids) .latest - .preload(:vocab_term_tags, :publication).find_each do |vocab_term| + .preload(:vocab_term_tags, :publication) + .find_each(batch_size: 100) do |vocab_term| VocabTerm.transaction do if vocab_term.is_published? vocab_term = vocab_term.new_version @@ -45,7 +47,10 @@ def up ).pluck(:id) exercise_ids = ExerciseTag.where(tag_id: old_rd_tag_ids).distinct.pluck(:exercise_id) - Exercise.where(id: exercise_ids).latest.preload(:exercise_tags).find_each do |exercise| + Exercise.where(id: exercise_ids) + .latest + .preload(:exercise_tags) + .find_each(batch_size: 100) do |exercise| Exercise.transaction do if exercise.is_published? exercise = exercise.new_version @@ -60,7 +65,10 @@ def up end vocab_term_ids = VocabTermTag.where(tag_id: old_rd_tag_ids).distinct.pluck(:vocab_term_id) - VocabTerm.where(id: vocab_term_ids).latest.preload(:vocab_term_tags).find_each do |vocab_term| + VocabTerm.where(id: vocab_term_ids) + .latest + .preload(:vocab_term_tags) + .find_each(batch_size: 100) do |vocab_term| VocabTerm.transaction do if vocab_term.is_published? vocab_term = vocab_term.new_version