diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-07-19 00:09:08 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:43:08 -0500 |
commit | e301f705eeb4f863acceb9eb141e6cf4ff6e15b7 (patch) | |
tree | 9f785591d254777108d77b5e1ac37aa2ff49aa09 | |
parent | dc5526f4ae8c9d3a6f132b2bc72914b95e5286cc (diff) |
[Database] Move lengthy backfill for computing post nesting levels to Rake task, monsterfork:compute_nesting_levels
-rw-r--r-- | lib/tasks/monsterfork.rake (renamed from db/migrate/20200717015413_backfill_status_nest_level.rb) | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/db/migrate/20200717015413_backfill_status_nest_level.rb b/lib/tasks/monsterfork.rake index 1f37ef847..041bdac3c 100644 --- a/db/migrate/20200717015413_backfill_status_nest_level.rb +++ b/lib/tasks/monsterfork.rake @@ -1,24 +1,22 @@ -class BackfillStatusNestLevel < ActiveRecord::Migration[5.2] - disable_ddl_transaction! - - def up - Rails.logger.info("Populating nest levels for orphaned replies...") +# frozen_string_literal: true +namespace :monsterfork do + desc 'Compute post nesting levels (this may take a very long time!)' + task compute_nesting_levels: :environment do + Rails.logger.info('Setting post nesting level for orphaned replies...') Status.select(:id, :account_id).where(reply: true, in_reply_to_id: nil).reorder(nil).in_batches.update_all(nest_level: 1) count = 1.0 total = Conversation.count Conversation.reorder('conversations.id DESC').find_each do |conversation| - Rails.logger.info("(#{(count/total*100).to_i}%) Populating nest levels for threads...") + Rails.logger.info("(#{(count / total * 100).to_i}%) Computing post nesting levels for all threads...") + conversation.statuses.where(reply: true).reorder('statuses.id ASC').find_each do |status| level = [status.thread&.account_id == status.account_id ? status.thread&.nest_level.to_i : status.thread&.nest_level.to_i + 1, 127].min status.update(nest_level: level) if level != status.nest_level end + count += 1 end end - - def down - true - end end |