New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move account counters to separate table #9295

Merged
merged 1 commit into from Nov 18, 2018

Conversation

Projects
None yet
2 participants
@Gargron
Copy link
Member

Gargron commented Nov 16, 2018

statuses_count is the most updated column probably among all tables, because it goes up every time you post a new status. By extracting it to a table with only a few columns, updates can run faster and the dead tuples left behind until next vacuum are smaller.

Fix #7908

Instructions:

  1. Run SKIP_POST_DEPLOYMENT_MIGRATIONS=true rails db:migrate first
  2. Restart Mastodon
  3. Run rails db:migrate

@Gargron Gargron added the performance label Nov 16, 2018

end

def increment_count!(key)
update_account_stat!(key => public_send(key) + 1)

This comment has been minimized.

@nightpool

nightpool Nov 17, 2018

Collaborator

i think this should maybe be attributes[key]? or something similar, i can't remember the precise syntax offhand.

This comment has been minimized.

@Gargron

Gargron Nov 18, 2018

Author Member

That's if the counter was on the same table as before. We want to call the explicitly defined followers_count method here.

@Gargron Gargron force-pushed the feature-account-stat branch 3 times, most recently from 7971ab1 to 12e6781 Nov 17, 2018

@@ -31,7 +31,7 @@ def ordered_instances
end

def subscribeable_accounts
Account.with_followers.remote.where(domain: params[:by_domain])
Account.remote.where(protocol: :ostatus).where(domain: params[:by_domain])

This comment has been minimized.

@Gargron

Gargron Nov 18, 2018

Author Member

Note: This query has been wrong for a long time. I think it hasn't been updated since ActivityPub was introduced. It would send PuSH subscriptions to ActivityPub accounts. It also would not correctly filter accounts that had local followers. So this is a net improvement.

end

def statuses_count
account_stat&.statuses_count || 0

This comment has been minimized.

@nightpool

nightpool Nov 18, 2018

Collaborator

should be delegate :statuses_count, :statuses_count=, :following_count, :following_count=, :followers_count, :followers_count=, to: :account_stat

and then handle the case of nil account_stat in the set_account_stat hook

This comment has been minimized.

@nightpool

nightpool Nov 18, 2018

Collaborator

%w(statuses following followers).flat_map { |i| [:"#{i}_count", :"#{i}_count=" } is even a little cuter, your call.

private

def set_account_stat
self.account_stat = build_account_stat if account_stat.nil?

This comment has been minimized.

@nightpool

nightpool Nov 18, 2018

Collaborator

per our conversation, this should handle migrating the counts from the existing record if there's no account_stat record.

@Gargron Gargron force-pushed the feature-account-stat branch from 12e6781 to 397b4e9 Nov 18, 2018

super || build_account_stat
end

def increment_count!(key)

This comment has been minimized.

@nightpool

nightpool Nov 18, 2018

Collaborator

i think these should live on AccountStat and be delegated also


private

def update_account_stat!(attrs)

This comment has been minimized.

@nightpool

nightpool Nov 18, 2018

Collaborator

and then we don't need to care about this method

@Gargron Gargron force-pushed the feature-account-stat branch from 397b4e9 to 2efad1f Nov 18, 2018

@Gargron Gargron force-pushed the feature-account-stat branch from 2efad1f to 4bf0f20 Nov 18, 2018

@Gargron Gargron merged commit d6b9a62 into master Nov 18, 2018

11 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: check-i18n Your tests passed on CircleCI!
Details
ci/circleci: install Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.3 Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.4 Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.5 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.3 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.4 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.5 Your tests passed on CircleCI!
Details
ci/circleci: test-webui Your tests passed on CircleCI!
Details
codeclimate Approved by Eugen.
Details

@Gargron Gargron deleted the feature-account-stat branch Nov 18, 2018

Gargron added a commit that referenced this pull request Nov 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment