You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. class MigrateAccountConversations < ActiveRecord::Migration[5.2]
  2. disable_ddl_transaction!
  3. def up
  4. say ''
  5. say 'WARNING: This migration may take a *long* time for large instances'
  6. say 'It will *not* lock tables for any significant time, but it may run'
  7. say 'for a very long time. We will pause for 10 seconds to allow you to'
  8. say 'interrupt this migration if you are not ready.'
  9. say ''
  10. 10.downto(1) do |i|
  11. say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
  12. sleep 1
  13. end
  14. local_direct_statuses.find_each do |status|
  15. AccountConversation.add_status(status.account, status)
  16. end
  17. notifications_about_direct_statuses.find_each do |notification|
  18. AccountConversation.add_status(notification.account, notification.target_status)
  19. end
  20. end
  21. def down
  22. end
  23. private
  24. def local_direct_statuses
  25. Status.unscoped
  26. .local
  27. .where(visibility: :direct)
  28. .includes(:account, mentions: :account)
  29. end
  30. def notifications_about_direct_statuses
  31. Notification.joins(mention: :status)
  32. .where(activity_type: 'Mention', statuses: { visibility: :direct })
  33. .includes(:account, mention: { status: [:account, mentions: :account] })
  34. end
  35. end