preload some more things

for planner and calendar events api

also apparently the except(:preload) makes it so
the inverse association for course on enrollments isn't set

Change-Id: Id490aa6b76c7c0b283a6c4a8be13ef2e5d4d9707
Reviewed-on: https://gerrit.instructure.com/160897
Tested-by: Jenkins
Reviewed-by: Mysti Sadler <mysti@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2018-08-15 11:24:01 -06:00
parent 6a36bcc3f5
commit 945013200e
3 changed files with 6 additions and 4 deletions

View File

@ -375,6 +375,7 @@ class CalendarEventsApiController < ApplicationController
calendar_events, assignments = events.partition { |e| e.is_a?(CalendarEvent) }
ActiveRecord::Associations::Preloader.new.preload(calendar_events, [:context, :parent_event])
ActiveRecord::Associations::Preloader.new.preload(assignments, Api::V1::Assignment::PRELOADS)
ActiveRecord::Associations::Preloader.new.preload(assignments.map(&:context), [:account, :grading_period_groups])
json = events.map do |event|
subs = submissions[event.id] if submissions

View File

@ -1509,7 +1509,7 @@ class Course < ActiveRecord::Base
is_unpublished = self.created? || self.claimed?
@enrollment_lookup ||= {}
@enrollment_lookup[user.id] ||= shard.activate do
self.enrollments.active_or_pending.for_user(user).except(:preload).preload(:enrollment_state).
self.enrollments.active_or_pending.for_user(user).preload(:enrollment_state).to_a.
reject { |e| (is_unpublished && !(e.admin? || e.fake_student?)) || [:inactive, :completed].include?(e.state_based_on_date)}
end

View File

@ -92,11 +92,12 @@ module Api::V1::PlannerItem
end
end
ActiveRecord::Associations::Preloader.new.preload(preload_items, :planner_overrides, ::PlannerOverride.where(user: user))
_events, other_items = preload_items.partition{|i| i.is_a?(::CalendarEvent)}
events, other_items = preload_items.partition{|i| i.is_a?(::CalendarEvent)}
ActiveRecord::Associations::Preloader.new.preload(events, :context) if events.any?
notes, context_items = other_items.partition{|i| i.is_a?(::PlannerNote)}
ActiveRecord::Associations::Preloader.new.preload(notes, user: {pseudonym: :account}) if notes.any?
wiki_pages, other_context_items = context_items.partition{|i| i.is_a?(::WikiPage)}
ActiveRecord::Associations::Preloader.new.preload(wiki_pages, wiki: [{course: :root_account}, {group: :root_account}]) if wiki_pages.any?
ActiveRecord::Associations::Preloader.new.preload(wiki_pages, {context: :root_account}) if wiki_pages.any?
ActiveRecord::Associations::Preloader.new.preload(other_context_items, {context: :root_account}) if other_context_items.any?
ss = user.submission_statuses(opts)
discussions, _assign_quiz_items = other_context_items.partition{|i| i.is_a?(::DiscussionTopic)}