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.

66 lines
1.5 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. attr_accessor :failure_days
  12. has_many :accounts, foreign_key: :domain, primary_key: :domain
  13. belongs_to :domain_block, foreign_key: :domain, primary_key: :domain
  14. belongs_to :domain_allow, foreign_key: :domain, primary_key: :domain
  15. belongs_to :unavailable_domain, foreign_key: :domain, primary_key: :domain # skipcq: RB-RL1031
  16. scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
  17. def self.refresh
  18. Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
  19. end
  20. def readonly?
  21. true
  22. end
  23. def delivery_failure_tracker
  24. @delivery_failure_tracker ||= DeliveryFailureTracker.new(domain)
  25. end
  26. def following_count
  27. @following_count ||= Follow.where(account: accounts).count
  28. end
  29. def followers_count
  30. @followers_count ||= Follow.where(target_account: accounts).count
  31. end
  32. def reports_count
  33. @reports_count ||= Report.where(target_account: accounts).count
  34. end
  35. def blocks_count
  36. @blocks_count ||= Block.where(target_account: accounts).count
  37. end
  38. def public_comment
  39. domain_block&.public_comment
  40. end
  41. def private_comment
  42. domain_block&.private_comment
  43. end
  44. def media_storage
  45. @media_storage ||= MediaAttachment.where(account: accounts).sum(:file_file_size)
  46. end
  47. def to_param
  48. domain
  49. end
  50. end