-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Conversation
end | ||
|
||
def increment_count!(key) | ||
update_account_stat!(key => public_send(key) + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this should maybe be attributes[key]
? or something similar, i can't remember the precise syntax offhand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's if the counter was on the same table as before. We want to call the explicitly defined followers_count
method here.
7971ab1
to
12e6781
Compare
@@ -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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per our conversation, this should handle migrating the counts from the existing record if there's no account_stat record.
12e6781
to
397b4e9
Compare
super || build_account_stat | ||
end | ||
|
||
def increment_count!(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think these should live on AccountStat and be delegated also
|
||
private | ||
|
||
def update_account_stat!(attrs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then we don't need to care about this method
397b4e9
to
2efad1f
Compare
2efad1f
to
4bf0f20
Compare
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:
SKIP_POST_DEPLOYMENT_MIGRATIONS=true rails db:migrate
first