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.

14 lines
850 B

  1. class AddCounterCaches < ActiveRecord::Migration[5.0]
  2. def change
  3. add_column :statuses, :favourites_count, :integer
  4. add_column :statuses, :reblogs_count, :integer
  5. execute('update statuses set favourites_count = (select count(*) from favourites where favourites.status_id = statuses.id), reblogs_count = (select count(*) from statuses as reblogs where reblogs.reblog_of_id = statuses.id)')
  6. add_column :accounts, :statuses_count, :integer
  7. add_column :accounts, :followers_count, :integer
  8. add_column :accounts, :following_count, :integer
  9. execute('update accounts set statuses_count = (select count(*) from statuses where account_id = accounts.id), followers_count = (select count(*) from follows where target_account_id = accounts.id), following_count = (select count(*) from follows where account_id = accounts.id)')
  10. end
  11. end