From 37f00fb01811f379d0f2978d5b9fa6cec031e7c7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 19 Nov 2024 05:36:02 -0500 Subject: [PATCH] Use hash arguments to `group` when possible (#32916) --- app/lib/annual_report/most_reblogged_accounts.rb | 2 +- app/lib/annual_report/most_used_apps.rb | 2 +- app/models/account_filter.rb | 2 +- app/models/poll.rb | 4 ++-- app/models/user.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/lib/annual_report/most_reblogged_accounts.rb b/app/lib/annual_report/most_reblogged_accounts.rb index 5c750b19bf..69e247f2a6 100644 --- a/app/lib/annual_report/most_reblogged_accounts.rb +++ b/app/lib/annual_report/most_reblogged_accounts.rb @@ -17,6 +17,6 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source private def most_reblogged_accounts - report_statuses.where.not(reblog_of_id: nil).joins(reblog: :account).group('accounts.id').having('count(*) > 1').order(count_all: :desc).limit(SET_SIZE).count + report_statuses.where.not(reblog_of_id: nil).joins(reblog: :account).group(accounts: [:id]).having('count(*) > 1').order(count_all: :desc).limit(SET_SIZE).count end end diff --git a/app/lib/annual_report/most_used_apps.rb b/app/lib/annual_report/most_used_apps.rb index e10ba52503..a2e1aca452 100644 --- a/app/lib/annual_report/most_used_apps.rb +++ b/app/lib/annual_report/most_used_apps.rb @@ -17,6 +17,6 @@ class AnnualReport::MostUsedApps < AnnualReport::Source private def most_used_apps - report_statuses.joins(:application).group('oauth_applications.name').order(count_all: :desc).limit(SET_SIZE).count + report_statuses.joins(:application).group(oauth_applications: [:name]).order(count_all: :desc).limit(SET_SIZE).count end end diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb index e2f359a8c3..f5e9fc7db9 100644 --- a/app/models/account_filter.rb +++ b/app/models/account_filter.rb @@ -61,7 +61,7 @@ class AccountFilter when 'email' accounts_with_users.merge(User.matches_email(value.to_s.strip)) when 'ip' - valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value).group('users.id, accounts.id')) : Account.none + valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value).group(users: [:id], accounts: [:id])) : Account.none when 'invited_by' invited_by_scope(value) when 'order' diff --git a/app/models/poll.rb b/app/models/poll.rb index cc4184f80a..ebd4644094 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -29,8 +29,8 @@ class Poll < ApplicationRecord has_many :votes, class_name: 'PollVote', inverse_of: :poll, dependent: :delete_all with_options class_name: 'Account', source: :account, through: :votes do - has_many :voters, -> { group('accounts.id') } - has_many :local_voters, -> { group('accounts.id').merge(Account.local) } + has_many :voters, -> { group(accounts: [:id]) } + has_many :local_voters, -> { group(accounts: [:id]).merge(Account.local) } end has_many :notifications, as: :activity, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index be9ebac699..c90a78f0cc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -125,7 +125,7 @@ class User < ApplicationRecord scope :signed_in_recently, -> { where(current_sign_in_at: ACTIVE_DURATION.ago..) } scope :not_signed_in_recently, -> { where(current_sign_in_at: ...ACTIVE_DURATION.ago) } scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) } - scope :matches_ip, ->(value) { left_joins(:ips).merge(IpBlock.contained_by(value)).group('users.id') } + scope :matches_ip, ->(value) { left_joins(:ips).merge(IpBlock.contained_by(value)).group(users: [:id]) } before_validation :sanitize_role before_create :set_approved