Last active
August 6, 2022 14:18
-
-
Save scytacki/7bc2bf33c0fde7753fcc353de3c9f547 to your computer and use it in GitHub Desktop.
copy-half-width-setting.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ManagedInteractive.where("legacy_ref_id is not null").where("updated_at < '2022-08-04'").count | |
Embeddable::OpenResponse.joins(:converted_interactive).where(is_half_width: true).count + | |
Embeddable::MultipleChoice.joins(:converted_interactive).where(is_half_width: true).count + | |
Embeddable::ImageQuestion.joins(:converted_interactive).where(is_half_width: true).count + | |
VideoInteractive.joins(:converted_interactive).where(is_half_width: true).count + | |
ImageInteractive.joins(:converted_interactive).where(is_half_width: true).count | |
def author_modified_count | |
ManagedInteractive.where("legacy_ref_id is not null").where("updated_at > '2022-08-04'").count | |
end | |
# mis_updated = [] | |
def copy_half_width_setting | |
mis_processed = 0 | |
mis_updated = 0 | |
managed_interactives = ManagedInteractive.where("legacy_ref_id is not null").where("updated_at < '2022-08-04'").includes(:legacy_ref) | |
mis_to_process = managed_interactives.count | |
managed_interactives.find_in_batches(batch_size: 1000) { |batch| | |
ActiveRecord::Base.transaction { | |
batch.each { |mi| | |
if (mi.legacy_ref.is_half_width && !mi.is_half_width) | |
# Use update_column so the updated_at time is not changed | |
mi.update_column(:is_half_width, mi.legacy_ref.is_half_width) | |
mis_updated += 1 | |
end | |
mis_processed += 1 | |
} | |
puts "#{mis_processed} of #{mis_to_process} processed." | |
} | |
} | |
puts "Processed #{mis_processed} of #{mis_to_process}. #{mis_updated} updated" | |
end | |
# Result from authoring-migrate | |
# Processed 320839 of 320839. 313833 updated | |
# Result from authoring | |
# Processed 320796 of 320796. 313799 updated | |
# Generate CSV of what was modified this requires an array of mis_updated ids | |
# This isn't really feasible because it will be around 50 MB of text to copy | |
output = CSV.generate { |csv| | |
mis_updated.each_slice(100) { |mi_ids| | |
mis = ManagedInteractive.where(id: mi_ids) | |
mis.each{ |mi| | |
page = mi.interactive_page | |
activity = page&.lightweight_activity | |
next if !page || !activity | |
csv << [ | |
mi.id, | |
activity.project.title, | |
activity.user.email, | |
"https://authoring.concord.org/activities/#{activity.id}/pages/#{page.id}/edit" | |
] | |
} | |
} | |
};nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment