about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/accounts_controller.rb4
-rw-r--r--app/controllers/admin/accounts_controller.rb27
-rw-r--r--app/controllers/application_controller.rb4
-rw-r--r--app/controllers/tags_controller.rb5
4 files changed, 34 insertions, 6 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index b0e5a8320..46231dd97 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -9,12 +9,12 @@ class AccountsController < ApplicationController
   def show
     respond_to do |format|
       format.html do
-        @statuses = @account.statuses.order('id desc').paginate_by_max_id(20, params[:max_id || nil])
+        @statuses = @account.statuses.order('id desc').paginate_by_max_id(20, params[:max_id], params[:since_id])
         @statuses = cache_collection(@statuses, Status)
       end
 
       format.atom do
-        @entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id] || nil)
+        @entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
       end
     end
   end
diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb
index e84799040..79fb37eb9 100644
--- a/app/controllers/admin/accounts_controller.rb
+++ b/app/controllers/admin/accounts_controller.rb
@@ -2,12 +2,37 @@
 
 class Admin::AccountsController < ApplicationController
   before_action :require_admin!
+  before_action :set_account, except: :index
 
   layout 'public'
 
   def index
+    @accounts = Account.order('domain ASC, username ASC').paginate(page: params[:page], per_page: 40)
+
+    @accounts = @accounts.local                             if params[:local].present?
+    @accounts = @accounts.remote                            if params[:remote].present?
+    @accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present?
+    @accounts = @accounts.where(silenced: true)             if params[:silenced].present?
+    @accounts = @accounts.reorder('id desc')                if params[:recent].present?
+  end
+
+  def show; end
+
+  def update
+    if @account.update(account_params)
+      redirect_to admin_accounts_path
+    else
+      render :show
+    end
+  end
+
+  private
+
+  def set_account
+    @account = Account.find(params[:id])
   end
 
-  def show
+  def account_params
+    params.require(:account).permit(:silenced)
   end
 end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index fbe4af07c..7270686de 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -61,7 +61,7 @@ class ApplicationController < ActionController::Base
   def cache_collection(raw, klass)
     return raw unless klass.respond_to?(:with_includes)
 
-    raw                    = raw.select(:id, :updated_at).to_a if raw.is_a?(ActiveRecord::Relation)
+    raw                    = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
     uncached_ids           = []
     cached_keys_with_value = Rails.cache.read_multi(*raw.map(&:cache_key))
 
@@ -69,6 +69,8 @@ class ApplicationController < ActionController::Base
       uncached_ids << item.id unless cached_keys_with_value.key?(item.cache_key)
     end
 
+    klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!)
+
     unless uncached_ids.empty?
       uncached = klass.where(id: uncached_ids).with_includes.map { |item| [item.id, item] }.to_h
 
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 4a70b2a8f..6b6c73080 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -4,7 +4,8 @@ class TagsController < ApplicationController
   layout 'public'
 
   def show
-    @statuses = Tag.find_by!(name: params[:id].downcase).statuses.order('id desc').paginate_by_max_id(20, params[:max_id] || nil)
-  	@statuses = cache_collection(@statuses, Status)
+    @tag      = Tag.find_by!(name: params[:id].downcase)
+    @statuses = @tag.statuses.order('id desc').paginate_by_max_id(20, params[:max_id])
+    @statuses = cache_collection(@statuses, Status)
   end
 end