searchable: replace find_ordered with in_order_of.
Rails 7 added an `in_order_of` method that does what our `find_ordered` method did before.
This commit is contained in:
@@ -592,7 +592,7 @@ module Searchable
|
|||||||
if params[:order] == "custom"
|
if params[:order] == "custom"
|
||||||
parse_ids = PostQueryBuilder.new(nil).parse_range(params[:id], :integer)
|
parse_ids = PostQueryBuilder.new(nil).parse_range(params[:id], :integer)
|
||||||
if parse_ids[0] == :in
|
if parse_ids[0] == :in
|
||||||
return find_ordered(parse_ids[1])
|
return in_order_of(:id, parse_ids[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -603,14 +603,6 @@ module Searchable
|
|||||||
order(id: :desc)
|
order(id: :desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_ordered(ids)
|
|
||||||
order_clause = []
|
|
||||||
ids.each do |id|
|
|
||||||
order_clause << sanitize_sql_array(["#{qualified_column_for(:id)} = ? DESC", id])
|
|
||||||
end
|
|
||||||
where(id: ids).order(Arel.sql(order_clause.join(', ')))
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def qualified_column_for(attr)
|
def qualified_column_for(attr)
|
||||||
|
|||||||
@@ -736,7 +736,7 @@ class PostQueryBuilder
|
|||||||
operator, ids = parse_range(id_metatags.first, :integer)
|
operator, ids = parse_range(id_metatags.first, :integer)
|
||||||
return relation.none unless operator == :in
|
return relation.none unless operator == :in
|
||||||
|
|
||||||
relation.find_ordered(ids)
|
relation.in_order_of(:id, ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @raise [TagLimitError] if the number of tags exceeds the user's tag limit
|
# @raise [TagLimitError] if the number of tags exceeds the user's tag limit
|
||||||
|
|||||||
@@ -962,7 +962,7 @@ class Post < ApplicationRecord
|
|||||||
random_up(key) || random_down(key)
|
random_up(key) || random_down(key)
|
||||||
end.compact.uniq
|
end.compact.uniq
|
||||||
|
|
||||||
reorder(nil).find_ordered(posts.map(&:id))
|
reorder(nil).in_order_of(:id, posts.map(&:id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def random_up(key)
|
def random_up(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user