about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-01-08 13:39:49 +0100
committerGitHub <noreply@github.com>2019-01-08 13:39:49 +0100
commit1c6588accca23599ea1537ec527a5be04408b2af (patch)
treefd0b7af844699dc38829e776ff5a42987b6b1193 /app/models
parent9a38357111049c7587c898b2b623cf9c853a4d35 (diff)
Redesign admin instances area (#9645)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/instance.rb21
-rw-r--r--app/models/instance_filter.rb17
2 files changed, 20 insertions, 18 deletions
diff --git a/app/models/instance.rb b/app/models/instance.rb
index 6d5c9c2ab..7448d465c 100644
--- a/app/models/instance.rb
+++ b/app/models/instance.rb
@@ -3,10 +3,23 @@
 class Instance
   include ActiveModel::Model
 
-  attr_accessor :domain, :accounts_count
+  attr_accessor :domain, :accounts_count, :domain_block
 
-  def initialize(account)
-    @domain = account.domain
-    @accounts_count = account.accounts_count
+  def initialize(resource)
+    @domain         = resource.domain
+    @accounts_count = resource.accounts_count
+    @domain_block   = resource.is_a?(DomainBlock) ? resource : DomainBlock.find_by(domain: domain)
+  end
+
+  def cached_sample_accounts
+    Rails.cache.fetch("#{cache_key}/sample_accounts", expires_in: 12.hours) { Account.where(domain: domain).searchable.joins(:account_stat).popular.limit(3) }
+  end
+
+  def to_param
+    domain
+  end
+
+  def cache_key
+    domain
   end
 end
diff --git a/app/models/instance_filter.rb b/app/models/instance_filter.rb
index 5073cf1fa..3483d8cd6 100644
--- a/app/models/instance_filter.rb
+++ b/app/models/instance_filter.rb
@@ -8,21 +8,10 @@ class InstanceFilter
   end
 
   def results
-    scope = Account.remote.by_domain_accounts
-    params.each do |key, value|
-      scope.merge!(scope_for(key, value)) if value.present?
-    end
-    scope
-  end
-
-  private
-
-  def scope_for(key, value)
-    case key.to_s
-    when 'domain_name'
-      Account.matches_domain(value)
+    if params[:limited].present?
+      DomainBlock.order(id: :desc)
     else
-      raise "Unknown filter: #{key}"
+      Account.remote.by_domain_accounts
     end
   end
 end