From 13d19afe6a9e344e0e9b6a9206f90e98f75d32d7 Mon Sep 17 00:00:00 2001 From: takayamaki Date: Wed, 12 Dec 2018 17:40:53 +0900 Subject: [PATCH] =?UTF-8?q?=E6=99=82=E9=96=93=E3=81=8C=E3=81=8B=E3=81=8B?= =?UTF-8?q?=E3=82=8B=E3=83=9E=E3=82=A4=E3=82=B0=E3=83=AC=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92rake=E3=82=BF=E3=82=B9=E3=82=AF?= =?UTF-8?q?=E3=81=AB=E5=88=87=E3=82=8A=E5=87=BA=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...024224956_migrate_account_conversations.rb | 35 +------------------ lib/tasks/mastodon.rake | 21 +++++++++++ 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/db/migrate/20181024224956_migrate_account_conversations.rb b/db/migrate/20181024224956_migrate_account_conversations.rb index b718f9e1d524e7..fdb35b0c9ec7d6 100644 --- a/db/migrate/20181024224956_migrate_account_conversations.rb +++ b/db/migrate/20181024224956_migrate_account_conversations.rb @@ -2,40 +2,7 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - say '' - say 'WARNING: This migration may take a *long* time for large instances' - say 'It will *not* lock tables for any significant time, but it may run' - say 'for a very long time. We will pause for 10 seconds to allow you to' - say 'interrupt this migration if you are not ready.' - say '' - - 10.downto(1) do |i| - say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true - sleep 1 - end - - migrated = 0 - last_time = Time.zone.now - - local_direct_statuses.includes(:account, mentions: :account).find_each do |status| - AccountConversation.add_status(status.account, status) - migrated += 1 - - if Time.zone.now - last_time > 1 - say_progress(migrated) - last_time = Time.zone.now - end - end - - notifications_about_direct_statuses.includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification| - AccountConversation.add_status(notification.account, notification.target_status) - migrated += 1 - - if Time.zone.now - last_time > 1 - say_progress(migrated) - last_time = Time.zone.now - end - end + # migrated to rake task end def down diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index ee9657b0eff06c..6bb8d63ac8b33b 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -4,6 +4,27 @@ require 'tty-command' require 'tty-prompt' namespace :mastodon do + namespace :migrate do + desc 'migrate AccountConversation' + task accountConversation: :environment do + migrated = 0 + Status.unscoped.local.where(visibility: :direct).includes(:account, mentions: :account).find_each do |status| + AccountConversation.add_status(status.account, status) + migrated += 1 + + puts "Migrated #{migrated} rows" + end + + puts + Notification.joins(mention: :status).where(activity_type: 'Mention', statuses: { visibility: :direct }).includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification| + AccountConversation.add_status(notification.account, notification.target_status) + migrated += 1 + + puts "Migrated #{migrated} rows" + end + end + end + desc 'Configure the instance for production use' task :setup do prompt = TTY::Prompt.new