Skip to content

Commit

Permalink
perf(reference timeline): improve performance of reference timeline e…
Browse files Browse the repository at this point in the history
…ager loading
  • Loading branch information
ekowidianto committed Apr 8, 2024
1 parent 805ce69 commit 950c8ce
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index
@items_hash = @course.lesson_plan_items.where(actable_id: @assessments.pluck(:id),
actable_type: Course::Assessment.name).
preload(actable: :conditions).
with_reference_times_for(current_course_user).
with_reference_times_for(current_course_user, current_course).
with_personal_times_for(current_course_user).
to_h do |item|
[item.actable_id, item]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def load_items_with_timeline # rubocop:disable Metrics/CyclomaticComplexity
*@assessment_todos&.map { |todo| todo.item.id },
*@survey_todos&.map { |todo| todo.item.id }]
@todo_items_with_timeline_hash = @course.lesson_plan_items.where(id: item_ids).
with_reference_times_for(current_course_user).
with_reference_times_for(current_course_user, current_course).
with_personal_times_for(current_course_user).
to_h do |item|
[item.id, item]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course/personal_times_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
# Only show for assessments and videos
@items = @course.lesson_plan_items.where(actable_type: [Course::Assessment.name, Course::Video.name]).
ordered_by_date_and_title.
with_reference_times_for(@course_user).
with_reference_times_for(@course_user, @course).
with_personal_times_for(@course_user)

render 'index'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course/video/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def preload_video_item
@video_items_hash = @course.lesson_plan_items.where(actable_id: @videos.pluck(:id),
actable_type: Course::Video.name).
preload(actable: :conditions).
with_reference_times_for(current_course_user).
with_reference_times_for(current_course_user, current_course).
with_personal_times_for(current_course_user).
to_h do |item|
[item.actable_id, item]
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/lesson_plan/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Course::LessonPlan::Item < ApplicationRecord
# Loads the reference times for `course_user`. If `course_user` is nil, then we load the default reference time for
# `course`.
scope :with_reference_times_for, (lambda do |course_user, course = nil|
# Can't eager-load if we have no idea who we are eager-loading for
# Even if there's no course user, we can eager load if the course is known.
return if course_user.nil? && course.nil?

default_reference_timeline_id = course_user&.course&.default_reference_timeline&.id ||
Expand Down

0 comments on commit 950c8ce

Please sign in to comment.