diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-12-07 12:08:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 12:08:30 +0100 |
commit | 48bef17cc990afda95c4de657f7643c321e62650 (patch) | |
tree | 01636821b1bbf46667e625bd842ee0bde65470d8 | |
parent | a8c471fcc043b61aa10cf8f849dfb552db7381d3 (diff) |
Fix slow distinct queries where grouped queries are faster (#15287)
About 2x speed-up on inboxes query
-rw-r--r-- | app/controllers/accounts_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/admin/statuses_controller.rb | 2 | ||||
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/form/account_batch.rb | 2 |
4 files changed, 4 insertions, 4 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index ccb5ef8e8..b902ada09 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -81,7 +81,7 @@ class AccountsController < ApplicationController end def account_media_status_ids - @account.media_attachments.attached.reorder(nil).select(:status_id).distinct + @account.media_attachments.attached.reorder(nil).select(:status_id).group(:status_id) end def no_replies_scope diff --git a/app/controllers/admin/statuses_controller.rb b/app/controllers/admin/statuses_controller.rb index 650195034..d7c192f0d 100644 --- a/app/controllers/admin/statuses_controller.rb +++ b/app/controllers/admin/statuses_controller.rb @@ -14,7 +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).distinct + 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)) end diff --git a/app/models/account.rb b/app/models/account.rb index f794d8a29..ed11a514d 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -443,7 +443,7 @@ class Account < ApplicationRecord end def inboxes - urls = reorder(nil).where(protocol: :activitypub).pluck(Arel.sql("distinct coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url)")) + urls = reorder(nil).where(protocol: :activitypub).group(:preferred_inbox_url).pluck(Arel.sql("coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url) AS preferred_inbox_url")) DeliveryFailureTracker.without_unavailable(urls) end diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb index 882770d7c..26d6d3abf 100644 --- a/app/models/form/account_batch.rb +++ b/app/models/form/account_batch.rb @@ -51,7 +51,7 @@ class Form::AccountBatch end def account_domains - accounts.pluck(Arel.sql('distinct domain')).compact + accounts.group(:domain).pluck(:domain).compact end def accounts |