闭社主体 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.

29 lines
811 B

  1. # frozen_string_literal: true
  2. class Instance
  3. include ActiveModel::Model
  4. attr_accessor :domain, :accounts_count, :domain_block
  5. def initialize(resource)
  6. @domain = resource.domain
  7. @accounts_count = resource.is_a?(DomainBlock) ? nil : resource.accounts_count
  8. @domain_block = resource.is_a?(DomainBlock) ? resource : DomainBlock.find_by(domain: domain)
  9. end
  10. def cached_sample_accounts
  11. Rails.cache.fetch("#{cache_key}/sample_accounts", expires_in: 12.hours) { Account.where(domain: domain).searchable.joins(:account_stat).popular.limit(3) }
  12. end
  13. def cached_accounts_count
  14. @accounts_count || Rails.cache.fetch("#{cache_key}/count", expires_in: 12.hours) { Account.where(domain: domain).count }
  15. end
  16. def to_param
  17. domain
  18. end
  19. def cache_key
  20. domain
  21. end
  22. end