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.

63 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: instances
  5. #
  6. # domain :string primary key
  7. # accounts_count :bigint(8)
  8. #
  9. class Instance < ApplicationRecord
  10. self.primary_key = :domain
  11. has_many :accounts, foreign_key: :domain, primary_key: :domain
  12. belongs_to :domain_block, foreign_key: :domain, primary_key: :domain
  13. belongs_to :domain_allow, foreign_key: :domain, primary_key: :domain
  14. scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
  15. def self.refresh
  16. Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
  17. end
  18. def readonly?
  19. true
  20. end
  21. def delivery_failure_tracker
  22. @delivery_failure_tracker ||= DeliveryFailureTracker.new(domain)
  23. end
  24. def following_count
  25. @following_count ||= Follow.where(account: accounts).count
  26. end
  27. def followers_count
  28. @followers_count ||= Follow.where(target_account: accounts).count
  29. end
  30. def reports_count
  31. @reports_count ||= Report.where(target_account: accounts).count
  32. end
  33. def blocks_count
  34. @blocks_count ||= Block.where(target_account: accounts).count
  35. end
  36. def public_comment
  37. domain_block&.public_comment
  38. end
  39. def private_comment
  40. domain_block&.private_comment
  41. end
  42. def media_storage
  43. @media_storage ||= MediaAttachment.where(account: accounts).sum(:file_file_size)
  44. end
  45. def to_param
  46. domain
  47. end
  48. end