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.

31 lines
621 B

  1. # frozen_string_literal: true
  2. module AccountCounters
  3. extend ActiveSupport::Concern
  4. included do
  5. has_one :account_stat, inverse_of: :account
  6. after_save :save_account_stat
  7. end
  8. delegate :statuses_count,
  9. :statuses_count=,
  10. :following_count,
  11. :following_count=,
  12. :followers_count,
  13. :followers_count=,
  14. :increment_count!,
  15. :decrement_count!,
  16. to: :account_stat
  17. def account_stat
  18. super || build_account_stat
  19. end
  20. private
  21. def save_account_stat
  22. return unless account_stat&.changed?
  23. account_stat.save
  24. end
  25. end