fixed 项目优化排序
This commit is contained in:
parent
79d46231ba
commit
575dbb0544
|
@ -17,6 +17,7 @@ class Projects::ListQuery < ApplicationQuery
|
||||||
sort = params[:sort_by] || "updated_on"
|
sort = params[:sort_by] || "updated_on"
|
||||||
sort_direction = params[:sort_direction] || "desc"
|
sort_direction = params[:sort_direction] || "desc"
|
||||||
|
|
||||||
|
collection = optimize_sorting(collection, sort)
|
||||||
custom_sort(collection, sort, sort_direction)
|
custom_sort(collection, sort, sort_direction)
|
||||||
|
|
||||||
# scope = scope.reorder("projects.#{sort} #{sort_direction}")
|
# scope = scope.reorder("projects.#{sort} #{sort_direction}")
|
||||||
|
@ -57,5 +58,20 @@ class Projects::ListQuery < ApplicationQuery
|
||||||
def by_pinned(items)
|
def by_pinned(items)
|
||||||
(params[:pinned].present? && params[:category_id].present?) ? items.pinned : items
|
(params[:pinned].present? && params[:category_id].present?) ? items.pinned : items
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 优化排序
|
||||||
|
def optimize_sorting(relations, sort_by)
|
||||||
|
if sort_by == "updated_on"
|
||||||
|
relations.where("projects.updated_on>'2010-01-01'")
|
||||||
|
elsif sort_by == "created_on"
|
||||||
|
relations.where("projects.created_on>'2010-01-01'")
|
||||||
|
elsif sort_by == "forked_count"
|
||||||
|
relations.where("projects.forked_count>=0")
|
||||||
|
elsif sort_by == "praises_count"
|
||||||
|
relations.where("projects.praises_count>=0")
|
||||||
|
else
|
||||||
|
relations
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue