1
0

account_stat.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. # last_status_at :datetime
  14. #
  15. class AccountStat < ApplicationRecord
  16. self.locking_column = nil
  17. self.ignored_columns += %w(lock_version)
  18. belongs_to :account, inverse_of: :account_stat
  19. scope :by_recent_status, -> { order(arel_table[:last_status_at].desc.nulls_last) }
  20. scope :without_recent_activity, -> { where(last_status_at: [nil, ...1.month.ago]) }
  21. update_index('accounts', :account)
  22. def following_count
  23. [attributes['following_count'], 0].max
  24. end
  25. def followers_count
  26. [attributes['followers_count'], 0].max
  27. end
  28. def statuses_count
  29. [attributes['statuses_count'], 0].max
  30. end
  31. end