2018-11-19 10:43:52 +11:00
|
|
|
# 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!,
|
2018-12-07 03:36:11 +11:00
|
|
|
:last_status_at,
|
2018-11-19 10:43:52 +11:00
|
|
|
to: :account_stat
|
|
|
|
|
|
|
|
def account_stat
|
|
|
|
super || build_account_stat
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def save_account_stat
|
2019-08-18 22:55:03 +10:00
|
|
|
return unless association(:account_stat).loaded? && account_stat&.changed?
|
|
|
|
|
2018-11-19 10:43:52 +11:00
|
|
|
account_stat.save
|
|
|
|
end
|
|
|
|
end
|