首页搜索问题

dev_local
daiao 5 years ago
parent 951f1a76bc
commit 808edb593b

@ -26,14 +26,7 @@ class ShixunsController < ApplicationController
## 获取课程列表 ## 获取课程列表
def index def index
## 我的实训 @shixuns = current_laboratory.shixuns.unhidden.publiced
@shixuns =
if params[:order_by] == 'mine'
tip_exception(401, "..") unless current_user.logged?
current_user.my_shixuns
else
Shixun.unhidden
end
## 方向 ## 方向
if params[:tag_level].present? && params[:tag_id].present? if params[:tag_level].present? && params[:tag_id].present?
@ -72,16 +65,12 @@ class ShixunsController < ApplicationController
end end
## 排序参数 ## 排序参数
bsort = params[:sort] || 'desc' bsort = (params[:sort] == "desc" ? "desc" : "asc")
case params[:order_by] || 'publish_time' case params[:order_by] || 'new'
when 'new'
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}")
when 'hot' when 'hot'
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") @shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.myshixuns_count #{bsort}")
when 'mine'
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
else else
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") @shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.publish_time #{bsort}")
end end
# 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。 # 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。
@ -92,12 +81,6 @@ class ShixunsController < ApplicationController
limit = params[:limit] || 16 limit = params[:limit] || 16
@shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit)
@tag_name_map = TagRepertoire.joins(:shixun_tag_repertoires)
.where(shixun_tag_repertoires: { shixun_id: @shixuns.map(&:id) })
.group('shixun_tag_repertoires.shixun_id')
.select('shixun_id, tag_repertoires.name')
.each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name }
end end
def shixun_list def shixun_list

Loading…
Cancel
Save