diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-06-27 14:22:30 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-09-08 03:37:04 -0500 |
commit | 9d4f18b984d6699bdf96e5f5963edfe80063426c (patch) | |
tree | e00fb54963769a259cd9bbe97754a2a872d028be /lib/tasks/monsterfork.rake | |
parent | 437d71bddf967573df3912ee5976f7c5a5a7b4c7 (diff) |
Monsterfork v2 Kaiju Commit 2020.06.27.1 - 2020.09.05.5
Diffstat (limited to 'lib/tasks/monsterfork.rake')
-rw-r--r-- | lib/tasks/monsterfork.rake | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/tasks/monsterfork.rake b/lib/tasks/monsterfork.rake new file mode 100644 index 000000000..041bdac3c --- /dev/null +++ b/lib/tasks/monsterfork.rake @@ -0,0 +1,22 @@ +# 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}%) 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 +end |