This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix performance on instances list in admin UI (mastodon#15282)
- Reduce duplicate queries - Remove n+1 queries - Add accounts count to detailed view - Add separate action log entry for updating existing domain blocks
- Loading branch information
Showing
27 changed files
with
326 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DomainMaterializable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
after_create_commit :refresh_instances_view | ||
end | ||
|
||
def refresh_instances_view | ||
Instance.refresh unless domain.nil? || Instance.where(domain: domain).exists? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,63 @@ | ||
# frozen_string_literal: true | ||
# == Schema Information | ||
# | ||
# Table name: instances | ||
# | ||
# domain :string primary key | ||
# accounts_count :bigint(8) | ||
# | ||
|
||
class Instance | ||
include ActiveModel::Model | ||
class Instance < ApplicationRecord | ||
self.primary_key = :domain | ||
|
||
attr_accessor :domain, :accounts_count, :domain_block | ||
has_many :accounts, foreign_key: :domain, primary_key: :domain | ||
|
||
def initialize(resource) | ||
@domain = resource.domain | ||
@accounts_count = resource.respond_to?(:accounts_count) ? resource.accounts_count : nil | ||
@domain_block = resource.is_a?(DomainBlock) ? resource : DomainBlock.rule_for(domain) | ||
@domain_allow = resource.is_a?(DomainAllow) ? resource : DomainAllow.rule_for(domain) | ||
belongs_to :domain_block, foreign_key: :domain, primary_key: :domain | ||
belongs_to :domain_allow, foreign_key: :domain, primary_key: :domain | ||
|
||
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } | ||
|
||
def self.refresh | ||
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false) | ||
end | ||
|
||
def countable? | ||
@accounts_count.present? | ||
def readonly? | ||
true | ||
end | ||
|
||
def to_param | ||
domain | ||
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 | ||
end | ||
|
||
def cache_key | ||
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 | ||
domain | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,10 @@ def create? | |
admin? | ||
end | ||
|
||
def update? | ||
admin? | ||
end | ||
|
||
def destroy? | ||
admin? | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.directory__tag | ||
= link_to admin_instance_path(instance) do | ||
%h4 | ||
= instance.domain | ||
%small | ||
- if instance.domain_block | ||
- first_item = true | ||
- if !instance.domain_block.noop? | ||
= t("admin.domain_blocks.severity.#{instance.domain_block.severity}") | ||
- first_item = false | ||
- unless instance.domain_block.suspend? | ||
- if instance.domain_block.reject_media? | ||
- unless first_item | ||
• | ||
= t('admin.domain_blocks.rejecting_media') | ||
- first_item = false | ||
- if instance.domain_block.reject_reports? | ||
- unless first_item | ||
• | ||
= t('admin.domain_blocks.rejecting_reports') | ||
- elsif whitelist_mode? | ||
= t('admin.accounts.whitelisted') | ||
- else | ||
= t('admin.accounts.no_limits_imposed') | ||
.trends__item__current{ title: t('admin.instances.known_accounts', count: instance.accounts_count) }= number_to_human instance.accounts_count, strip_insignificant_zeros: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.