FIX: Make /categories/search order deterministic (#25793)
This commit is contained in:
parent
47623e1214
commit
bf7470e93b
|
@ -382,16 +382,6 @@ class CategoriesController < ApplicationController
|
|||
|
||||
categories = categories.limit(limit || MAX_CATEGORIES_LIMIT)
|
||||
|
||||
categories = categories.order(<<~SQL) if prioritized_category_id.present?
|
||||
CASE
|
||||
WHEN id = #{prioritized_category_id} THEN 1
|
||||
WHEN parent_category_id = #{prioritized_category_id} THEN 2
|
||||
ELSE 3
|
||||
END
|
||||
SQL
|
||||
|
||||
categories = categories.order(:id)
|
||||
|
||||
Category.preload_user_fields!(guardian, categories)
|
||||
|
||||
# Prioritize categories that start with the term, then top-level
|
||||
|
@ -401,6 +391,9 @@ class CategoriesController < ApplicationController
|
|||
[
|
||||
category.name.downcase.starts_with?(term) ? 0 : 1,
|
||||
category.parent_category_id.blank? ? 0 : 1,
|
||||
category.id == prioritized_category_id ? 0 : 1,
|
||||
category.parent_category_id == prioritized_category_id ? 0 : 1,
|
||||
category.id,
|
||||
]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue