Skip to content

Commit 7d77006

Browse files
committed
Revert "Optimize getting exercises in a course"
This reverts commit 6e4282d.
1 parent 6e4282d commit 7d77006

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

app/controllers/api/v8/courses/exercises_controller.rb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,8 @@ def index
3434
course = Course.find_by!(id: params[:course_id]) if params[:course_id]
3535
exercises = Exercise.includes(:available_points).where(course_id: course.id)
3636

37-
unlocked_exercises = course.unlocks
38-
.where(user_id: current_user.id)
39-
.where(['valid_after IS NULL OR valid_after < ?', Time.now])
40-
.pluck(:exercise_name)
41-
42-
unless current_user.administrator? || current_user.teacher?(course.organization) || current_user.assistant?(course)
43-
exercises = exercises.where(hidden: false, disabled_status: 0)
44-
exercises = if unlocked_exercises.empty?
45-
exercises.where(unlock_spec: nil)
46-
else
47-
exercises.where(["unlock_spec IS NULL OR name IN (#{unlocked_exercises.map { |_| '?' }.join(', ')})", *unlocked_exercises])
48-
end.select { |e| e._fast_visible_to?(current_user) }
49-
end
50-
51-
presentable = exercises.map do |ex|
37+
visible = exercises.select { |ex| ex.visible_to?(current_user) }
38+
presentable = visible.map do |ex|
5239
{
5340
id: ex.id,
5441
available_points: ex.available_points,
@@ -60,7 +47,8 @@ def index
6047
}
6148
end
6249

63-
render json: presentable
50+
authorize_collection :read, visible
51+
present(presentable)
6452
end
6553
end
6654
end

0 commit comments

Comments
 (0)