课程首页性能优化

dev_course
jingquan huang 6 years ago
parent 82edc4c9a9
commit 5b3752275c

@ -54,12 +54,12 @@ class CoursesController < ApplicationController
# u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and
# c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id")
# @courses = Course.where(is_delete: 0, is_hidden: 0).includes([teacher: :user_extension], :school)
@courses = Course.where(is_delete: 0, is_hidden: 0).includes(:course_modules, :course_members, teacher: [user_extension: :school])
@courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count,
courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at)
FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a")
.order("courses.id = 1309 desc, a desc")
# @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count,
# courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at)
# FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a")
# .order("courses.id = 1309 desc, a desc")
elsif @order == "mine"
@courses = Course.joins(:course_members)
.where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id)
@ -103,6 +103,7 @@ class CoursesController < ApplicationController
# GET /courses/1
# GET /courses/1.json
def show
# render :json => {first_category_url: module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).first, course)}
end
# GET /courses/new

@ -7,7 +7,7 @@ class Course < ApplicationRecord
has_many :course_infos, dependent: :destroy
# 课堂左侧导航栏的模块
has_many :course_modules, dependent: :destroy
has_many :course_modules, -> {where hidden: 0}, dependent: :destroy
has_many :board_course_modules, -> { board_module }, class_name: "CourseModule"
has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule"
has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule"

@ -10,9 +10,9 @@ json.courses do
json.tasks_count get_tasks_count course
json.visits course.visits
json.is_public course.is_public
json.is_accessible @user.present? ? @user.member_of_course?(course) || @user.creator_of_course?(course) : course.is_public == 1
json.is_accessible course.is_public? ? true : (course.tea_id == @user.id || @user.course_identity(course) < 5)
json.is_end course.is_end
json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course)
json.first_category_url module_url(course.course_modules.first, course)
end
end
json.courses_count @courses_count

Loading…
Cancel
Save