DEV: Fix order: filter not working on /filter route (#21330)

`TopicQuery#latest_results` which was being used by
`TopicQuery#list_filter` defaults to ordering by `Topic#bumped_at` in
descending order and that was taking precedent over the order scopes
being applied by `TopicsFilter`.
This commit is contained in:
Alan Guo Xiang Tan
2023-05-03 12:40:00 +08:00
committed by GitHub
parent 691b9fb919
commit c12e7112bf
2 changed files with 38 additions and 3 deletions

View File

@ -270,7 +270,10 @@ class TopicQuery
def list_filter
topics_filter =
TopicsFilter.new(guardian: @guardian, scope: latest_results(include_muted: false))
TopicsFilter.new(
guardian: @guardian,
scope: latest_results(include_muted: false, skip_ordering: true),
)
results = topics_filter.filter_from_query_string(@options[:q])
@ -278,6 +281,8 @@ class TopicQuery
results = remove_muted_topics(results, @user)
end
results = apply_ordering(results) if results.order_values.empty?
create_list(:filter, {}, results)
end
@ -618,7 +623,7 @@ class TopicQuery
result.where("topics.category_id != ?", drafts_category_id)
end
def apply_ordering(result, options)
def apply_ordering(result, options = {})
sort_column = SORTABLE_MAPPING[options[:order]] || "default"
sort_dir = (options[:ascending] == "true") ? "ASC" : "DESC"
@ -732,7 +737,7 @@ class TopicQuery
result = filter_by_tags(result)
end
result = apply_ordering(result, options)
result = apply_ordering(result, options) if !options[:skip_ordering]
all_listable_topics =
@guardian.filter_allowed_categories(