Use hash arguments to order when possible (Rails 7.2) (#32915)

This commit is contained in:
Matt Jankowski
2024-11-18 10:07:53 -05:00
committed by GitHub
parent 477412d62a
commit da826fe959
4 changed files with 11 additions and 11 deletions

View File

@@ -61,7 +61,7 @@ class Tag < ApplicationRecord
scope :recently_used, lambda { |account|
joins(:statuses)
.where(statuses: { id: account.statuses.select(:id).limit(RECENT_STATUS_LIMIT) })
.group(:id).order(Arel.sql('count(*) desc'))
.group(:id).order(Arel.star.count.desc)
}
scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index
@@ -127,7 +127,7 @@ class Tag < ApplicationRecord
query = query.merge(Tag.listable) if options[:exclude_unlistable]
query = query.merge(matching_name(stripped_term).or(reviewed)) if options[:exclude_unreviewed]
query.order(Arel.sql('length(name) ASC, name ASC'))
query.order(Arel.sql('LENGTH(name)').asc, name: :asc)
.limit(limit)
.offset(offset)
end