FIX: Make /categories/search order deterministic (#25793)

This commit is contained in:
Daniel Waterworth 2024-02-21 12:20:40 -06:00 committed by GitHub
parent 47623e1214
commit bf7470e93b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 10 deletions

View File

@ -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