闭社主体 forked from https://github.com/tootsuite/mastodon
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.

26 lines
711 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: account_stats
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8) not null
  8. # statuses_count :bigint(8) default(0), not null
  9. # following_count :bigint(8) default(0), not null
  10. # followers_count :bigint(8) default(0), not null
  11. # created_at :datetime not null
  12. # updated_at :datetime not null
  13. #
  14. class AccountStat < ApplicationRecord
  15. belongs_to :account, inverse_of: :account_stat
  16. def increment_count!(key)
  17. update(key => public_send(key) + 1)
  18. end
  19. def decrement_count!(key)
  20. update(key => [public_send(key) - 1, 0].max)
  21. end
  22. end