about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/instances_controller.rb15
-rw-r--r--app/models/account.rb1
-rw-r--r--app/views/admin/instances/index.html.haml15
3 files changed, 31 insertions, 0 deletions
diff --git a/app/controllers/admin/instances_controller.rb b/app/controllers/admin/instances_controller.rb
new file mode 100644
index 000000000..b8f170ec2
--- /dev/null
+++ b/app/controllers/admin/instances_controller.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Admin
+  class InstancesController < BaseController
+    def index
+      @instances = ordered_instances.page(params[:page])
+    end
+
+    private
+
+    def ordered_instances
+      Account.remote.by_domain_accounts
+    end
+  end
+end
diff --git a/app/models/account.rb b/app/models/account.rb
index 2a10f8345..f8a6dd703 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -68,6 +68,7 @@ class Account < ApplicationRecord
   scope :suspended, -> { where(suspended: true) }
   scope :recent, -> { reorder(id: :desc) }
   scope :alphabetic, -> { order(domain: :asc, username: :asc) }
+  scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
 
   def follow!(other_account)
     active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
diff --git a/app/views/admin/instances/index.html.haml b/app/views/admin/instances/index.html.haml
new file mode 100644
index 000000000..b5ad40ac6
--- /dev/null
+++ b/app/views/admin/instances/index.html.haml
@@ -0,0 +1,15 @@
+- content_for :page_title do
+  = t('admin.instances.title')
+
+%table.table
+  %thead
+    %tr
+      %th= t('admin.instances.domain_name')
+      %th= t('admin.instances.account_count')
+  %tbody
+    - @instances.each do |instance|
+      %tr
+        %td= instance.domain
+        %td= instance.accounts_count
+
+= paginate @instances