2017-05-31 19:38:44 +01:00
|
|
|
# frozen_string_literal: true
|
2020-12-14 08:06:34 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: instances
|
|
|
|
#
|
|
|
|
# domain :string primary key
|
|
|
|
# accounts_count :bigint(8)
|
|
|
|
#
|
2017-05-31 19:38:44 +01:00
|
|
|
|
2020-12-14 08:06:34 +00:00
|
|
|
class Instance < ApplicationRecord
|
|
|
|
self.primary_key = :domain
|
2017-05-31 19:38:44 +01:00
|
|
|
|
2021-05-05 22:39:02 +01:00
|
|
|
attr_accessor :failure_days
|
|
|
|
|
2020-12-14 08:06:34 +00:00
|
|
|
has_many :accounts, foreign_key: :domain, primary_key: :domain
|
2017-05-31 19:38:44 +01:00
|
|
|
|
2020-12-14 08:06:34 +00:00
|
|
|
belongs_to :domain_block, foreign_key: :domain, primary_key: :domain
|
|
|
|
belongs_to :domain_allow, foreign_key: :domain, primary_key: :domain
|
2021-05-05 22:39:02 +01:00
|
|
|
belongs_to :unavailable_domain, foreign_key: :domain, primary_key: :domain # skipcq: RB-RL1031
|
2020-12-14 08:06:34 +00:00
|
|
|
|
|
|
|
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
|
|
|
|
|
|
|
|
def self.refresh
|
|
|
|
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
2019-01-08 12:39:49 +00:00
|
|
|
end
|
|
|
|
|
2020-12-14 08:06:34 +00:00
|
|
|
def readonly?
|
|
|
|
true
|
2019-03-25 23:36:35 +00:00
|
|
|
end
|
|
|
|
|
2020-12-14 08:06:34 +00:00
|
|
|
def delivery_failure_tracker
|
|
|
|
@delivery_failure_tracker ||= DeliveryFailureTracker.new(domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def following_count
|
|
|
|
@following_count ||= Follow.where(account: accounts).count
|
|
|
|
end
|
|
|
|
|
|
|
|
def followers_count
|
|
|
|
@followers_count ||= Follow.where(target_account: accounts).count
|
|
|
|
end
|
|
|
|
|
|
|
|
def reports_count
|
|
|
|
@reports_count ||= Report.where(target_account: accounts).count
|
2019-01-08 12:39:49 +00:00
|
|
|
end
|
|
|
|
|
2020-12-14 08:06:34 +00:00
|
|
|
def blocks_count
|
|
|
|
@blocks_count ||= Block.where(target_account: accounts).count
|
|
|
|
end
|
|
|
|
|
|
|
|
def public_comment
|
|
|
|
domain_block&.public_comment
|
|
|
|
end
|
|
|
|
|
|
|
|
def private_comment
|
|
|
|
domain_block&.private_comment
|
|
|
|
end
|
|
|
|
|
|
|
|
def media_storage
|
|
|
|
@media_storage ||= MediaAttachment.where(account: accounts).sum(:file_file_size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
2019-01-08 12:39:49 +00:00
|
|
|
domain
|
2017-05-31 19:38:44 +01:00
|
|
|
end
|
|
|
|
end
|