教师列表的性能优化

dev_forum
cxt 6 years ago
parent 4000eafe94
commit c5ace72b7a

@ -284,6 +284,7 @@ class CoursesController < ApplicationController
page = params[:page] || 1
limit = params[:limit] || 20
@teacher_list = @teacher_list.page(page).per(limit)
@teacher_list = @teacher_list.preload(:graduation_group, :user, :teacher_course_groups)
end
def apply_teachers

@ -7,9 +7,11 @@ json.teacher_list do
json.user_id teacher.user.id
json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
json.course_groups do
json.array! CourseGroup.where(id: TeacherCourseGroup.where(course_member_id: teacher.id, user_id: teacher.user.id, course_id: @course.id).pluck(:course_group_id)) do |course_group|
json.name course_group.name
json.id course_group.id
if @course.course_groups_count > 0
json.array! @course.course_groups.select{|group| teacher.teacher_course_groups.pluck(:course_group_id).include?(group.id)} do |course_group|
json.name course_group.name
json.id course_group.id
end
end
end
json.graduation_group teacher.graduation_group.try(:name)

Loading…
Cancel
Save