about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
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