]> cat aescling's git repositories - mastodon.git/commitdiff
Improve media attached status query (#16105)
authorabcang <abcang1015@gmail.com>
Sun, 25 Apr 2021 04:34:48 +0000 (13:34 +0900)
committerGitHub <noreply@github.com>
Sun, 25 Apr 2021 04:34:48 +0000 (06:34 +0200)
app/controllers/accounts_controller.rb
app/controllers/admin/statuses_controller.rb
app/controllers/api/v1/accounts/statuses_controller.rb

index 7753ebccc67f8043fc1a349a26d2bfa26991145e..f159615527d04e7b9f4e4f4dca38be1a084672fa 100644 (file)
@@ -77,11 +77,7 @@ class AccountsController < ApplicationController
   end
 
   def only_media_scope
-    Status.where(id: account_media_status_ids)
-  end
-
-  def account_media_status_ids
-    @account.media_attachments.attached.reorder(nil).select(:status_id).group(:status_id)
+    Status.joins(:media_attachments).group(:id)
   end
 
   def no_replies_scope
index d7c192f0d6c9ed448d196339421f2f771253f811..df1bd1bc75e8da2dc8862b7fcc2742e7e0e7fa82 100644 (file)
@@ -14,8 +14,7 @@ module Admin
       @statuses = @account.statuses.where(visibility: [:public, :unlisted])
 
       if params[:media]
-        account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).group(:status_id)
-        @statuses.merge!(Status.where(id: account_media_status_ids))
+        @statuses.merge!(Status.joins(:media_attachments).group(:id))
       end
 
       @statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
index 92ccb80615da26ad94dbebf6edccefe7c7c14fa0..b1e478f8d75860aff3c80bd5bfebaa11dc80dc5e 100644 (file)
@@ -42,7 +42,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
   end
 
   def only_media_scope
-    Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id)
+    Status.joins(:media_attachments).group(:id)
   end
 
   def pinned_scope