Extract counters from accounts table to account_stats table (#9295)
This commit is contained in:
parent
4fdefffb99
commit
d6b9a62e0a
25 changed files with 203 additions and 68 deletions
31
app/models/concerns/account_counters.rb
Normal file
31
app/models/concerns/account_counters.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module AccountCounters
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_one :account_stat, inverse_of: :account
|
||||
after_save :save_account_stat
|
||||
end
|
||||
|
||||
delegate :statuses_count,
|
||||
:statuses_count=,
|
||||
:following_count,
|
||||
:following_count=,
|
||||
:followers_count,
|
||||
:followers_count=,
|
||||
:increment_count!,
|
||||
:decrement_count!,
|
||||
to: :account_stat
|
||||
|
||||
def account_stat
|
||||
super || build_account_stat
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def save_account_stat
|
||||
return unless account_stat&.changed?
|
||||
account_stat.save
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue