Skip to content

Commit

Permalink
Merge pull request #310 from openstax/migration_batch_size
Browse files Browse the repository at this point in the history
Reduced migration batch size to reduce memory pressure
  • Loading branch information
Dantemss authored Feb 5, 2021
2 parents 9f607aa + 6ffd37f commit 07b07c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 07b07c3

Please sign in to comment.