diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 36eebe4f2..64531a6f4 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -24,7 +24,7 @@ module CoursesHelper def find_excelletn_course keywords, current_course # 获取tag匹配结果ID a_tags = [] - Course.where("is_excellent =? and is_public =?", 1, 1).includes(:tags).each do |ec| + Course.where("is_excellent =? and is_public =?", 1, 1).each do |ec| if ec.tags.any?{|value| current_course.name.include?(value.to_s)} a_tags << ec.id end diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index a613d8984..6096b84cd 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -204,12 +204,18 @@ <% end%> <% end%> - <% course_order_ids = "(" + + <% if @user.courses.visible.count > 0 + course_order_ids = "(" + CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM (SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") GROUP BY ca.course_id) AS c - ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")"%> - <% courses = Course.where("id in #{course_order_ids}")%> + ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")" + courses = Course.where("id in #{course_order_ids}") + else + courses = [] + + end + %> <%# courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %>
- <% project_order_ids = "(" + + <% if @user.projects.visible.count > 0 + project_order_ids = "(" + ForgeActivity.find_by_sql("SELECT p.project_id, p.created_at FROM (SELECT fa.project_id, MAX(fa.created_at) AS created_at FROM forge_activities fa WHERE fa.project_id IN (" + @user.projects.visible.select('projects.id').map{|p| p.id}.join(',') + ") GROUP BY fa.project_id) AS p - ORDER BY p.created_at DESC limit 5").map {|p| p.project_id}.join(",") + ")"%> - <%# project_order_ids = "(" + ForgeActivity.select("DISTINCT project_id, max(created_at) as max_created_at").where("project_id in #{"(" + @user.projects.visible.select("projects.id").map{|p| p.id}.join(",") + ")"}").order("max_created_at desc").map {|p| p.project_id}.join(",") + ")"%> - <% projects = Project.where("projects.id in #{project_order_ids}")%> + ORDER BY p.created_at DESC limit 5").map {|p| p.project_id}.join(",") + ")" + projects = Project.where("projects.id in #{project_order_ids}") + else + projects = [] + end + %> + <%# projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>