use rails 4.2 preloader format
closes #CNVS-26031 Change-Id: I2e0351fb62e5a06b47fe8c6c3dd503318d29a7ad Reviewed-on: https://gerrit.instructure.com/69228 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins Product-Review: James Williams <jamesw@instructure.com> QA-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
7d473da7db
commit
c23210564c
|
@ -127,7 +127,7 @@ class AccountsController < ApplicationController
|
|||
else
|
||||
@accounts = []
|
||||
end
|
||||
ActiveRecord::Associations::Preloader.new(@accounts, :root_account).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@accounts, :root_account)
|
||||
|
||||
# originally had 'includes' instead of 'include' like other endpoints
|
||||
includes = params[:include] || params[:includes]
|
||||
|
@ -154,7 +154,7 @@ class AccountsController < ApplicationController
|
|||
else
|
||||
@accounts = []
|
||||
end
|
||||
ActiveRecord::Associations::Preloader.new(@accounts, :root_account).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@accounts, :root_account)
|
||||
render :json => @accounts.map { |a| account_json(a, @current_user, session, params[:includes] || [], true) }
|
||||
end
|
||||
|
||||
|
@ -175,7 +175,7 @@ class AccountsController < ApplicationController
|
|||
js_env(:ACCOUNT_COURSES_PATH => account_courses_path(@account, :format => :json))
|
||||
load_course_right_side
|
||||
@courses = @account.fast_all_courses(:term => @term, :limit => @maximum_courses_im_gonna_show, :hide_enrollmentless_courses => @hide_enrollmentless_courses)
|
||||
ActiveRecord::Associations::Preloader.new(@courses, :enrollment_term).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@courses, :enrollment_term)
|
||||
build_course_stats
|
||||
end
|
||||
format.json { render :json => account_json(@account, @current_user, session, params[:includes] || [],
|
||||
|
@ -238,7 +238,7 @@ class AccountsController < ApplicationController
|
|||
@accounts = Api.paginate(@accounts, self, api_v1_sub_accounts_url,
|
||||
:total_entries => recursive ? nil : @accounts.count)
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(@accounts, [:root_account, :parent_account]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@accounts, [:root_account, :parent_account])
|
||||
render :json => @accounts.map { |a| account_json(a, @current_user, session, []) }
|
||||
end
|
||||
|
||||
|
@ -368,8 +368,8 @@ class AccountsController < ApplicationController
|
|||
page_opts[:total_entries] = nil if params[:search_term] # doesn't calculate a total count
|
||||
@courses = Api.paginate(@courses, self, api_v1_account_courses_url, page_opts)
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(@courses, [:account, :root_account]).run
|
||||
ActiveRecord::Associations::Preloader.new(@courses, [:teachers]).run if includes.include?("teachers")
|
||||
ActiveRecord::Associations::Preloader.new.preload(@courses, [:account, :root_account])
|
||||
ActiveRecord::Associations::Preloader.new.preload(@courses, [:teachers]) if includes.include?("teachers")
|
||||
|
||||
if includes.include?("total_students")
|
||||
student_counts = StudentEnrollment.where("enrollments.workflow_state NOT IN ('rejected', 'completed', 'deleted', 'inactive')").
|
||||
|
@ -594,7 +594,7 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
load_course_right_side
|
||||
@account_users = @account.account_users
|
||||
ActiveRecord::Associations::Preloader.new(@account_users, user: :communication_channels).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@account_users, user: :communication_channels)
|
||||
order_hash = {}
|
||||
@account.available_account_roles.each_with_index do |role, idx|
|
||||
order_hash[role.id] = idx
|
||||
|
|
|
@ -257,7 +257,7 @@ class AppointmentGroupsController < ApplicationController
|
|||
api_v1_appointment_groups_url(:scope => params[:scope])
|
||||
)
|
||||
if params[:include]
|
||||
ActiveRecord::Associations::Preloader.new(groups,
|
||||
ActiveRecord::Associations::Preloader.new.preload(groups,
|
||||
[{:appointments =>
|
||||
[:parent_event,
|
||||
{:context =>
|
||||
|
@ -270,9 +270,9 @@ class AppointmentGroupsController < ApplicationController
|
|||
[:parent_event,
|
||||
:context]}]}]},
|
||||
{:appointment_group_contexts => :context},
|
||||
:appointment_group_sub_contexts]).run
|
||||
:appointment_group_sub_contexts])
|
||||
end
|
||||
render :json => groups.map{ |group| appointment_group_json(group, @current_user, session, :include => params[:include]) }
|
||||
render :json => groups.map{ |group| appointment_group_json(group, @current_user, session, :include => params[:include]) }
|
||||
end
|
||||
|
||||
# @API Create an appointment group
|
||||
|
@ -333,17 +333,17 @@ class AppointmentGroupsController < ApplicationController
|
|||
# @example_request
|
||||
#
|
||||
# curl 'https://<canvas>/api/v1/appointment_groups.json' \
|
||||
# -X POST \
|
||||
# -F 'appointment_group[context_codes][]=course_123' \
|
||||
# -F 'appointment_group[sub_context_codes][]=course_section_234' \
|
||||
# -F 'appointment_group[title]=Final Presentation' \
|
||||
# -X POST \
|
||||
# -F 'appointment_group[context_codes][]=course_123' \
|
||||
# -F 'appointment_group[sub_context_codes][]=course_section_234' \
|
||||
# -F 'appointment_group[title]=Final Presentation' \
|
||||
# -F 'appointment_group[participants_per_appointment]=1' \
|
||||
# -F 'appointment_group[min_appointments_per_participant]=1' \
|
||||
# -F 'appointment_group[max_appointments_per_participant]=1' \
|
||||
# -F 'appointment_group[new_appointments][0][]=2012-07-19T21:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][0][]=2012-07-19T22:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][1][]=2012-07-19T22:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][1][]=2012-07-19T23:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][0][]=2012-07-19T21:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][0][]=2012-07-19T22:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][1][]=2012-07-19T22:00:00Z' \
|
||||
# -F 'appointment_group[new_appointments][1][]=2012-07-19T23:00:00Z' \
|
||||
# -H "Authorization: Bearer <token>"
|
||||
def create
|
||||
contexts = get_contexts
|
||||
|
@ -441,7 +441,7 @@ class AppointmentGroupsController < ApplicationController
|
|||
# @example_request
|
||||
#
|
||||
# curl 'https://<canvas>/api/v1/appointment_groups/543.json' \
|
||||
# -X PUT \
|
||||
# -X PUT \
|
||||
# -F 'appointment_group[publish]=1' \
|
||||
# -H "Authorization: Bearer <token>"
|
||||
def update
|
||||
|
@ -460,7 +460,7 @@ class AppointmentGroupsController < ApplicationController
|
|||
|
||||
# @API Delete an appointment group
|
||||
#
|
||||
# Delete an appointment group (and associated time slots and reservations)
|
||||
# Delete an appointment group (and associated time slots and reservations)
|
||||
# and return the deleted group
|
||||
#
|
||||
# @argument cancel_reason [String]
|
||||
|
@ -469,8 +469,8 @@ class AppointmentGroupsController < ApplicationController
|
|||
# @example_request
|
||||
#
|
||||
# curl 'https://<canvas>/api/v1/appointment_groups/543.json' \
|
||||
# -X DELETE \
|
||||
# -F 'cancel_reason=El Tigre Chino got fired' \
|
||||
# -X DELETE \
|
||||
# -F 'cancel_reason=El Tigre Chino got fired' \
|
||||
# -H "Authorization: Bearer <token>"
|
||||
def destroy
|
||||
if authorized_action(@group, @current_user, :delete)
|
||||
|
|
|
@ -591,7 +591,7 @@ class AssignmentsApiController < ApplicationController
|
|||
override_param = params[:override_assignment_dates] || true
|
||||
override_dates = value_to_boolean(override_param)
|
||||
if override_dates || include_all_dates || include_override_objects
|
||||
ActiveRecord::Associations::Preloader.new(assignments, :assignment_overrides).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(assignments, :assignment_overrides)
|
||||
assignments.select{ |a| a.assignment_overrides.size == 0 }.
|
||||
each { |a| a.has_no_overrides = true }
|
||||
|
||||
|
|
|
@ -328,7 +328,7 @@ class CalendarEventsApiController < ApplicationController
|
|||
def render_events_for_user(user, route_url)
|
||||
scope = @type == :assignment ? assignment_scope(user) : calendar_event_scope(user)
|
||||
events = Api.paginate(scope, self, route_url)
|
||||
ActiveRecord::Associations::Preloader.new(events, :child_events).run if @type == :event
|
||||
ActiveRecord::Associations::Preloader.new.preload(events, :child_events) if @type == :event
|
||||
if @type == :assignment
|
||||
events = apply_assignment_overrides(events, user)
|
||||
mark_submitted_assignments(user, events)
|
||||
|
@ -642,7 +642,7 @@ class CalendarEventsApiController < ApplicationController
|
|||
@contexts.each do |context|
|
||||
log_asset_access([ "calendar_feed", context ], "calendar", 'other')
|
||||
end
|
||||
ActiveRecord::Associations::Preloader.new(@events, :context)
|
||||
ActiveRecord::Associations::Preloader.new.preload(@events, :context)
|
||||
|
||||
respond_to do |format|
|
||||
format.ics do
|
||||
|
@ -869,7 +869,7 @@ class CalendarEventsApiController < ApplicationController
|
|||
end
|
||||
|
||||
def apply_assignment_overrides(events, user)
|
||||
ActiveRecord::Associations::Preloader.new(events, [:context, :assignment_overrides]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(events, [:context, :assignment_overrides])
|
||||
events.each { |e| e.has_no_overrides = true if e.assignment_overrides.size == 0 }
|
||||
|
||||
if AssignmentOverrideApplicator.should_preload_override_students?(events, user, "calendar_events_api")
|
||||
|
@ -877,7 +877,7 @@ class CalendarEventsApiController < ApplicationController
|
|||
end
|
||||
|
||||
unless (params[:excludes] || []).include?('assignments')
|
||||
ActiveRecord::Associations::Preloader.new(events, [:rubric, :rubric_association]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(events, [:rubric, :rubric_association])
|
||||
# improves locked_json performance
|
||||
|
||||
student_events = events.select{|e| !e.context.grants_right?(user, session, :read_as_admin)}
|
||||
|
|
|
@ -223,7 +223,7 @@ class ContextModuleItemsApiController < ApplicationController
|
|||
def index
|
||||
if authorized_action(@context, @current_user, :read)
|
||||
mod = @context.modules_visible_to(@student || @current_user).find(params[:module_id])
|
||||
ActiveRecord::Associations::Preloader.new(mod, content_tags: :content).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(mod, content_tags: :content)
|
||||
route = polymorphic_url([:api_v1, @context, mod, :items])
|
||||
scope = mod.content_tags_visible_to(@student || @current_user)
|
||||
scope = ContentTag.search_by_attribute(scope, :title, params[:search_term])
|
||||
|
|
|
@ -358,7 +358,7 @@ class ContextModulesApiController < ApplicationController
|
|||
scope = ContextModule.search_by_attribute(scope, :name, params[:search_term]) unless includes.include?('items')
|
||||
modules = Api.paginate(scope, self, route)
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(modules, content_tags: :content) if includes.include?('items')
|
||||
ActiveRecord::Associations::Preloader.new.preload(modules, content_tags: :content) if includes.include?('items')
|
||||
|
||||
if @student
|
||||
modules_and_progressions = modules.map { |m| [m, m.evaluate_for(@student)] }
|
||||
|
@ -417,7 +417,7 @@ class ContextModulesApiController < ApplicationController
|
|||
if authorized_action(@context, @current_user, :read)
|
||||
mod = @context.modules_visible_to(@student || @current_user).find(params[:id])
|
||||
includes = Array(params[:include])
|
||||
ActiveRecord::Associations::Preloader.new(mod, content_tags: :content).run if includes.include?('items')
|
||||
ActiveRecord::Associations::Preloader.new.preload(mod, content_tags: :content) if includes.include?('items')
|
||||
prog = @student ? mod.evaluate_for(@student) : nil
|
||||
render :json => module_json(mod, @student || @current_user, session, prog, includes)
|
||||
end
|
||||
|
@ -436,12 +436,12 @@ class ContextModulesApiController < ApplicationController
|
|||
# @response_field completed A list of IDs for modules that were updated.
|
||||
#
|
||||
# @example_request
|
||||
# curl https://<canvas>/api/v1/courses/<course_id>/modules \
|
||||
# -X PUT \
|
||||
# curl https://<canvas>/api/v1/courses/<course_id>/modules \
|
||||
# -X PUT \
|
||||
# -H 'Authorization: Bearer <token>' \
|
||||
# -d 'event=delete' \
|
||||
# -d 'module_ids[]=1' \
|
||||
# -d 'module_ids[]=2'
|
||||
# -d 'module_ids[]=1' \
|
||||
# -d 'module_ids[]=2'
|
||||
#
|
||||
# @example_response
|
||||
# {
|
||||
|
|
|
@ -65,7 +65,7 @@ class ContextModulesController < ApplicationController
|
|||
|
||||
if @context.grants_right?(@current_user, session, :participate_as_student)
|
||||
return unless tab_enabled?(@context.class::TAB_MODULES)
|
||||
ActiveRecord::Associations::Preloader.new(@modules, :content_tags).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@modules, :content_tags)
|
||||
@modules.each{|m| m.evaluate_for(@current_user) }
|
||||
session[:module_progressions_initialized] = true
|
||||
end
|
||||
|
|
|
@ -530,7 +530,7 @@ class ConversationsController < ApplicationController
|
|||
messages = nil
|
||||
Shackles.activate(:slave) do
|
||||
messages = @conversation.messages
|
||||
ActiveRecord::Associations::Preloader.new(messages, :asset).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(messages, :asset)
|
||||
end
|
||||
|
||||
render :json => conversation_json(@conversation,
|
||||
|
|
|
@ -874,8 +874,8 @@ class CoursesController < ApplicationController
|
|||
if includes.include?('enrollments')
|
||||
# not_ended_enrollments for enrollment_json
|
||||
# enrollments course for has_grade_permissions?
|
||||
ActiveRecord::Associations::Preloader.new(users, {:not_ended_enrollments => :course},
|
||||
Enrollment.where(:course_id => @context)).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(users, {:not_ended_enrollments => :course},
|
||||
Enrollment.where(:course_id => @context))
|
||||
end
|
||||
user = users.first or raise ActiveRecord::RecordNotFound
|
||||
enrollments = user.not_ended_enrollments if includes.include?('enrollments')
|
||||
|
@ -1734,7 +1734,7 @@ class CoursesController < ApplicationController
|
|||
:search_method => @context.user_list_search_mode_for(@current_user),
|
||||
:initial_type => params[:enrollment_type])
|
||||
if !@context.concluded? && (@enrollments = EnrollmentsFromUserList.process(list, @context, enrollment_options))
|
||||
ActiveRecord::Associations::Preloader.new(@enrollments, [:course_section, {:user => [:communication_channel, :pseudonym]}]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@enrollments, [:course_section, {:user => [:communication_channel, :pseudonym]}])
|
||||
json = @enrollments.map { |e|
|
||||
{ 'enrollment' =>
|
||||
{ 'associated_user_id' => e.associated_user_id,
|
||||
|
@ -2418,7 +2418,7 @@ class CoursesController < ApplicationController
|
|||
enrollments_by_course = Api.paginate(enrollments_by_course, self, api_v1_courses_url) if api_request?
|
||||
if includes.include?("teachers")
|
||||
courses = enrollments_by_course.map(&:first).map(&:course)
|
||||
ActiveRecord::Associations::Preloader.new(courses, :teachers).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(courses, :teachers)
|
||||
end
|
||||
enrollments_by_course.each do |course_enrollments|
|
||||
course = course_enrollments.first.course
|
||||
|
|
|
@ -273,7 +273,7 @@ class EnrollmentsApiController < ApplicationController
|
|||
enrollments,
|
||||
self, send("api_v1_#{endpoint_scope}_enrollments_url"))
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(enrollments, [:user, :course, :course_section]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(enrollments, [:user, :course, :course_section])
|
||||
includes = [:user] + Array(params[:include])
|
||||
|
||||
user_json_preloads(enrollments.map(&:user))
|
||||
|
|
|
@ -305,7 +305,7 @@
|
|||
# paginate the indexed scope and then convert to actual Version records
|
||||
path = api_v1_gradebook_history_feed_url(@context, params)
|
||||
indexed_versions = Api.paginate(indexed_versions, self, path)
|
||||
ActiveRecord::Associations::Preloader.new(indexed_versions, :version).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(indexed_versions, :version)
|
||||
versions = indexed_versions.map(&:version).compact
|
||||
|
||||
render :json => versions_json(@context, versions, api_context(nil), :assignment => assignment, :student => student)
|
||||
|
|
|
@ -341,7 +341,7 @@ class OutcomeGroupsApiController < ApplicationController
|
|||
end
|
||||
|
||||
# preload the links' outcomes' contexts.
|
||||
ActiveRecord::Associations::Preloader.new(@links, :learning_outcome_content => :context).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@links, :learning_outcome_content => :context)
|
||||
|
||||
# render to json and serve
|
||||
render :json => outcome_links_json(@links, @current_user, session)
|
||||
|
|
|
@ -433,7 +433,7 @@ class OutcomeResultsController < ApplicationController
|
|||
@outcome_links += ContentTag.learning_outcome_links.active.where(associated_asset_id: outcome_group_ids_slice)
|
||||
end
|
||||
@outcome_links.each_slice(100) do |outcome_links_slice|
|
||||
ActiveRecord::Associations::Preloader.new(outcome_links_slice, :learning_outcome_content).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(outcome_links_slice, :learning_outcome_content)
|
||||
end
|
||||
@outcomes = @outcome_links.map(&:learning_outcome_content)
|
||||
end
|
||||
|
|
|
@ -125,7 +125,7 @@ class RoleOverridesController < ApplicationController
|
|||
roles += scope.where(:workflow_state => states).order(:id).to_a
|
||||
|
||||
roles = Api.paginate(roles, self, route)
|
||||
ActiveRecord::Associations::Preloader.new(roles, :account).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(roles, :account)
|
||||
render :json => roles.collect{|role| role_json(@context, role, @current_user, session)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,7 +88,7 @@ class SubAccountsController < ApplicationController
|
|||
|
||||
def show
|
||||
@sub_account = subaccount_or_self(params[:id])
|
||||
ActiveRecord::Associations::Preloader.new(@sub_account, [{:sub_accounts => [:parent_account, :root_account]}]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@sub_account, [{:sub_accounts => [:parent_account, :root_account]}])
|
||||
render :json => @sub_account.as_json(:only => [:id, :name], :methods => [:course_count, :sub_account_count],
|
||||
:include => [:sub_accounts => {:only => [:id, :name], :methods => [:course_count, :sub_account_count]}])
|
||||
end
|
||||
|
|
|
@ -844,8 +844,8 @@ class SubmissionsApiController < ApplicationController
|
|||
def bulk_load_attachments_and_previews(submissions)
|
||||
Submission.bulk_load_versioned_attachments(submissions)
|
||||
attachments = submissions.flat_map &:versioned_attachments
|
||||
ActiveRecord::Associations::Preloader.new(attachments,
|
||||
[:canvadoc, :crocodoc_document]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(attachments,
|
||||
[:canvadoc, :crocodoc_document])
|
||||
end
|
||||
|
||||
def bulk_process_submissions_for_visibility(submissions_scope, includes)
|
||||
|
|
|
@ -184,7 +184,7 @@ class UsersController < ApplicationController
|
|||
@grades = grades_for_presenter(@presenter, @grading_periods)
|
||||
js_env :grades_for_student_url => grades_for_student_url
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(@observed_enrollments, :course).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@observed_enrollments, :course)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ module SearchHelper
|
|||
end
|
||||
|
||||
add_groups = lambda do |groups, group_context = nil|
|
||||
ActiveRecord::Associations::Preloader.new(groups, :group_category).run
|
||||
ActiveRecord::Associations::Preloader.new(groups, :group_memberships, GroupMembership.where(user_id: @current_user)).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(groups, :group_category)
|
||||
ActiveRecord::Associations::Preloader.new.preload(groups, :group_memberships, GroupMembership.where(user_id: @current_user))
|
||||
groups.each do |group|
|
||||
group.can_participate = true
|
||||
contexts[:groups][group.id] = {
|
||||
|
|
|
@ -52,8 +52,8 @@ class AccountNotification < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# preload role objects for those enrollments and account users
|
||||
ActiveRecord::Associations::Preloader.new(enrollments, [:role]).run
|
||||
ActiveRecord::Associations::Preloader.new(account_users, [:role]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(enrollments, [:role])
|
||||
ActiveRecord::Associations::Preloader.new.preload(account_users, [:role])
|
||||
|
||||
# map to role ids. user role.id instead of role_id to trigger Role#id
|
||||
# magic for built in roles. announcements intended for users not
|
||||
|
|
|
@ -849,11 +849,11 @@ class Assignment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.preload_context_module_tags(assignments)
|
||||
ActiveRecord::Associations::Preloader.new(assignments, [
|
||||
ActiveRecord::Associations::Preloader.new.preload(assignments, [
|
||||
:context_module_tags,
|
||||
{ :discussion_topic => :context_module_tags },
|
||||
{ :quiz => :context_module_tags }
|
||||
]).run
|
||||
])
|
||||
end
|
||||
|
||||
def locked_for?(user, opts={})
|
||||
|
@ -1415,7 +1415,7 @@ class Assignment < ActiveRecord::Base
|
|||
|
||||
# if we're a provisional grader, calculate whether the student needs a grade
|
||||
preloaded_pg_counts = is_provisional && self.provisional_grades.not_final.group("submissions.user_id").count
|
||||
ActiveRecord::Associations::Preloader.new(self, :moderated_grading_selections).run if is_provisional # preload the association now
|
||||
ActiveRecord::Associations::Preloader.new.preload(self, :moderated_grading_selections) if is_provisional # preload the association now
|
||||
|
||||
res[:context][:students] = students.map do |u|
|
||||
json = u.as_json(:include_root => false,
|
||||
|
|
|
@ -474,7 +474,7 @@ class Conversation < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def subscribed_participants
|
||||
ActiveRecord::Associations::Preloader.new(conversation_participants, :user).run unless ModelCache[:users]
|
||||
ActiveRecord::Associations::Preloader.new.preload(conversation_participants, :user) unless ModelCache[:users]
|
||||
conversation_participants.select(&:subscribed?).map(&:user).compact
|
||||
end
|
||||
|
||||
|
|
|
@ -418,7 +418,7 @@ class Course < ActiveRecord::Base
|
|||
|
||||
if courses_or_course_ids.first.is_a? Course
|
||||
courses = courses_or_course_ids
|
||||
ActiveRecord::Associations::Preloader.new(courses, :course_sections => :nonxlist_course).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(courses, :course_sections => :nonxlist_course)
|
||||
course_ids = courses.map(&:id)
|
||||
else
|
||||
course_ids = courses_or_course_ids
|
||||
|
|
|
@ -307,7 +307,7 @@ class StreamItem < ActiveRecord::Base
|
|||
def self.prepare_object_for_unread(object)
|
||||
case object
|
||||
when DiscussionTopic
|
||||
ActiveRecord::Associations::Preloader.new(object, :discussion_topic_participants).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(object, :discussion_topic_participants)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -224,9 +224,9 @@ class SubmissionComment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.preload_attachments(comments)
|
||||
ActiveRecord::Associations::Preloader.new(comments, [:submission]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(comments, [:submission])
|
||||
submissions = comments.map(&:submission).uniq
|
||||
ActiveRecord::Associations::Preloader.new(submissions, :assignment => :attachments).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(submissions, :assignment => :attachments)
|
||||
end
|
||||
|
||||
def update_submission
|
||||
|
|
|
@ -1496,7 +1496,7 @@ class User < ActiveRecord::Base
|
|||
as = assignment_scope.active.
|
||||
expecting_submission.
|
||||
need_grading_info
|
||||
ActiveRecord::Associations::Preloader.new(as, :context).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(as, :context)
|
||||
as.lazy.select{|a| Assignments::NeedsGradingCountQuery.new(a, self).count != 0 }.take(opts[:limit]).to_a
|
||||
end
|
||||
end
|
||||
|
@ -1699,7 +1699,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
pending_enrollments = temporary_invitations
|
||||
unless pending_enrollments.empty?
|
||||
ActiveRecord::Associations::Preloader.new(pending_enrollments, :course).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(pending_enrollments, :course)
|
||||
res.concat(pending_enrollments.map do |e|
|
||||
c = e.course
|
||||
c.primary_enrollment_type = e.type
|
||||
|
@ -1751,7 +1751,7 @@ class User < ActiveRecord::Base
|
|||
if opts[:preload_dates]
|
||||
Canvas::Builders::EnrollmentDateBuilder.preload(enrollments)
|
||||
elsif opts[:preload_courses]
|
||||
ActiveRecord::Associations::Preloader.new(enrollments, :course).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(enrollments, :course)
|
||||
end
|
||||
enrollments
|
||||
end
|
||||
|
@ -1834,7 +1834,7 @@ class User < ActiveRecord::Base
|
|||
submissions = submissions.uniq
|
||||
submissions.first(opts[:limit])
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(submissions, [:assignment, :user, :submission_comments]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(submissions, [:assignment, :user, :submission_comments])
|
||||
submissions
|
||||
end
|
||||
end
|
||||
|
@ -2454,7 +2454,7 @@ class User < ActiveRecord::Base
|
|||
else
|
||||
@menu_courses = self.courses_with_primary_enrollment(:current_and_invited_courses, enrollment_uuid).first(12)
|
||||
end
|
||||
ActiveRecord::Associations::Preloader.new(@menu_courses, :enrollment_term).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@menu_courses, :enrollment_term)
|
||||
@menu_courses
|
||||
end
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ TEXT
|
|||
<% cache_key = cache_key_items.join('/') %>
|
||||
<% cache_key = add_menu_tools_to_cache_key(cache_key) %>
|
||||
<% cache(cache_key) do %>
|
||||
<% ActiveRecord::Associations::Preloader.new(@modules, :content_tags => :content).run %>
|
||||
<% ActiveRecord::Associations::Preloader.new.preload(@modules, :content_tags => :content) %>
|
||||
<% preload_can_unpublish(@context, @modules) %>
|
||||
<% @modules.each do |m| %>
|
||||
<%= render :partial => 'context_modules/context_module_next', :object => m, :locals => {:editable => editable} %>
|
||||
|
|
|
@ -664,7 +664,7 @@ ActiveRecord::Relation.class_eval do
|
|||
klass.unscoped do
|
||||
batch = connection.uncached { klass.find_by_sql("FETCH FORWARD #{batch_size} FROM #{cursor}") }
|
||||
while !batch.empty?
|
||||
ActiveRecord::Associations::Preloader.new(batch, includes).run if includes
|
||||
ActiveRecord::Associations::Preloader.new.preload(batch, includes) if includes
|
||||
yield batch
|
||||
break if batch.size < batch_size
|
||||
batch = connection.uncached { klass.find_by_sql("FETCH FORWARD #{batch_size} FROM #{cursor}") }
|
||||
|
@ -735,7 +735,7 @@ ActiveRecord::Relation.class_eval do
|
|||
batch = klass.find_by_sql(sql)
|
||||
end
|
||||
while !batch.empty?
|
||||
ActiveRecord::Associations::Preloader.new(batch, includes).run if includes
|
||||
ActiveRecord::Associations::Preloader.new.preload(batch, includes) if includes
|
||||
yield batch
|
||||
break if batch.size < batch_size
|
||||
|
||||
|
@ -1363,7 +1363,6 @@ module UnscopeCallbacks
|
|||
scope.scoping { super }
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Base.send(:include, UnscopeCallbacks)
|
||||
|
||||
ActiveRecord::DynamicMatchers::Method.class_eval do
|
||||
|
@ -1376,3 +1375,25 @@ ActiveRecord::DynamicMatchers::Method.class_eval do
|
|||
alias_method_chain :match, :discard
|
||||
end
|
||||
end
|
||||
|
||||
if CANVAS_RAILS4_0
|
||||
module PreloaderShim
|
||||
def initialize(*args)
|
||||
super unless args.empty?
|
||||
end
|
||||
|
||||
def preload(*args)
|
||||
if args.size == 1
|
||||
super
|
||||
else
|
||||
records, associations, preload_scope = args
|
||||
@records = Array.wrap(records).compact.uniq
|
||||
@associations = Array.wrap(associations)
|
||||
@preload_scope = preload_scope || ActiveRecord::Relation.new(nil, nil)
|
||||
run
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Associations::Preloader.send(:prepend, PreloaderShim)
|
||||
end
|
|
@ -43,7 +43,7 @@ module Api::V1::AssignmentOverride
|
|||
def assignment_override_collection(assignment, include_students=false)
|
||||
overrides = AssignmentOverrideApplicator.overrides_for_assignment_and_user(assignment, @current_user)
|
||||
if include_students
|
||||
ActiveRecord::Associations::Preloader.new(overrides, :assignment_override_students).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(overrides, :assignment_override_students)
|
||||
end
|
||||
overrides
|
||||
end
|
||||
|
@ -232,7 +232,7 @@ module Api::V1::AssignmentOverride
|
|||
existing_overrides = assignment.assignment_overrides.active
|
||||
|
||||
remaining_overrides = destroy_defunct_overrides(assignment, override_param_ids, existing_overrides)
|
||||
ActiveRecord::Associations::Preloader.new(remaining_overrides, :assignment_override_students).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(remaining_overrides, :assignment_override_students)
|
||||
|
||||
overrides = overrides_params.map do |override_params|
|
||||
override = get_override_from_params(override_params, assignment, remaining_overrides)
|
||||
|
|
|
@ -116,7 +116,7 @@ module Api::V1::CalendarEvent
|
|||
events = can_read_child_events ? event.child_events.to_a : event.child_events_for(participant)
|
||||
|
||||
# do some preloads
|
||||
ActiveRecord::Associations::Preloader.new(events, :context).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(events, :context)
|
||||
if events.first.context.is_a?(User) && user_json_is_admin?(@context, user)
|
||||
user_json_preloads(events.map(&:context))
|
||||
end
|
||||
|
@ -186,7 +186,7 @@ module Api::V1::CalendarEvent
|
|||
if include.include?('appointments')
|
||||
if include.include?('child_events')
|
||||
all_child_events = group.appointments.map(&:child_events).flatten
|
||||
ActiveRecord::Associations::Preloader.new(all_child_events, :context).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(all_child_events, :context)
|
||||
user_json_preloads(all_child_events.map(&:context)) if !all_child_events.empty? && all_child_events.first.context.is_a?(User) && user_json_is_admin?(@context, user)
|
||||
end
|
||||
hash['appointments'] = group.appointments.map { |event| calendar_event_json(event, user, session,
|
||||
|
|
|
@ -73,8 +73,8 @@ module Api::V1::Conversation
|
|||
end
|
||||
|
||||
def conversation_recipients_json(recipients, current_user, session)
|
||||
ActiveRecord::Associations::Preloader.new(recipients.select{|r| r.is_a?(MessageableUser)},
|
||||
{:pseudonym => :account}).run # for avatar_url
|
||||
ActiveRecord::Associations::Preloader.new.preload(recipients.select{|r| r.is_a?(MessageableUser)},
|
||||
{:pseudonym => :account}) # for avatar_url
|
||||
recipients.map do |recipient|
|
||||
if recipient.is_a?(MessageableUser)
|
||||
conversation_user_json(recipient, current_user, session,
|
||||
|
@ -93,7 +93,7 @@ module Api::V1::Conversation
|
|||
:include_participant_contexts => true
|
||||
}.merge(options)
|
||||
if options[:include_participant_avatars]
|
||||
ActiveRecord::Associations::Preloader.new(users, {:pseudonym => :account}).run # for avatar_url
|
||||
ActiveRecord::Associations::Preloader.new.preload(users, {:pseudonym => :account}) # for avatar_url
|
||||
end
|
||||
users.map { |user| conversation_user_json(user, current_user, session, options) }
|
||||
end
|
||||
|
|
|
@ -48,11 +48,11 @@ module Api::V1
|
|||
def versions_json(course, versions, api_context, opts={})
|
||||
# preload for efficiency
|
||||
unless opts[:submission]
|
||||
ActiveRecord::Associations::Preloader.new(versions, :versionable).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(versions, :versionable)
|
||||
submissions = versions.map(&:versionable)
|
||||
ActiveRecord::Associations::Preloader.new(submissions, :assignment).run unless opts[:assignment]
|
||||
ActiveRecord::Associations::Preloader.new(submissions, :user).run unless opts[:student]
|
||||
ActiveRecord::Associations::Preloader.new(submissions, :grader).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(submissions, :assignment) unless opts[:assignment]
|
||||
ActiveRecord::Associations::Preloader.new.preload(submissions, :user) unless opts[:student]
|
||||
ActiveRecord::Associations::Preloader.new.preload(submissions, :grader)
|
||||
end
|
||||
|
||||
versions.map do |version|
|
||||
|
|
|
@ -61,7 +61,7 @@ module Api::V1::OutcomeResults
|
|||
# Returns a Hash containing serialized outcomes.
|
||||
def outcome_results_include_outcomes_json(outcomes)
|
||||
outcomes.each_slice(50).each do |outcomes_slice|
|
||||
ActiveRecord::Associations::Preloader.new(outcomes_slice, [:context, :alignments]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(outcomes_slice, [:context, :alignments])
|
||||
end
|
||||
assessed_outcomes = []
|
||||
outcomes.map(&:id).each_slice(100) do |outcome_ids|
|
||||
|
|
|
@ -19,7 +19,7 @@ module Api::V1::Pseudonym
|
|||
end
|
||||
|
||||
def pseudonyms_json(pseudonyms, current_user, session)
|
||||
ActiveRecord::Associations::Preloader.new(pseudonyms, :authentication_provider).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(pseudonyms, :authentication_provider)
|
||||
pseudonyms.map do |p|
|
||||
pseudonym_json(p, current_user, session)
|
||||
end
|
||||
|
|
|
@ -22,11 +22,11 @@ module Api::V1::StreamItem
|
|||
|
||||
def stream_item_preloads(stream_items)
|
||||
discussion_topics = stream_items.select { |si| ['DiscussionTopic', 'Announcement'].include?(si.asset_type) }
|
||||
ActiveRecord::Associations::Preloader.new(discussion_topics, :context).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(discussion_topics, :context)
|
||||
assessment_requests = stream_items.select { |si| si.asset_type == 'AssessmentRequest' }.map(&:data)
|
||||
ActiveRecord::Associations::Preloader.new(assessment_requests, asset: :assignment).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(assessment_requests, asset: :assignment)
|
||||
submissions = stream_items.select { |si| si.asset_type == 'Submission' }
|
||||
ActiveRecord::Associations::Preloader.new(submissions, asset: { assignment: :context }).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(submissions, asset: { assignment: :context })
|
||||
end
|
||||
|
||||
def stream_item_json(stream_item_instance, stream_item, current_user, session)
|
||||
|
|
|
@ -28,14 +28,14 @@ module Api::V1::User
|
|||
|
||||
def user_json_preloads(users, preload_email=false)
|
||||
# for User#account
|
||||
ActiveRecord::Associations::Preloader.new(users, :pseudonym => :account).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(users, :pseudonym => :account)
|
||||
|
||||
# pseudonyms for User#sis_pseudoym_for and User#find_pseudonym_for_account
|
||||
# pseudonyms account for Pseudonym#works_for_account?
|
||||
ActiveRecord::Associations::Preloader.new(users, pseudonyms: :account).run if user_json_is_admin?
|
||||
ActiveRecord::Associations::Preloader.new.preload(users, pseudonyms: :account) if user_json_is_admin?
|
||||
if preload_email && (no_email_users = users.reject(&:email_cached?)).present?
|
||||
# communication_channels for User#email if it is not cached
|
||||
ActiveRecord::Associations::Preloader.new(no_email_users, :communication_channels).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(no_email_users, :communication_channels)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -109,7 +109,7 @@ module Api::V1::User
|
|||
def users_json(users, current_user, session, includes = [], context = @context, enrollments = nil, excludes = [])
|
||||
|
||||
if includes.include?('sections')
|
||||
ActiveRecord::Associations::Preloader.new(users, enrollments: :course_section).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(users, enrollments: :course_section)
|
||||
end
|
||||
|
||||
users.map{ |user| user_json(user, current_user, session, includes, context, enrollments, excludes) }
|
||||
|
|
|
@ -332,11 +332,11 @@ module AssignmentOverrideApplicator
|
|||
|
||||
def self.preload_assignment_override_students(items, user)
|
||||
return unless user
|
||||
ActiveRecord::Associations::Preloader.new(items, :context).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(items, :context)
|
||||
# preloads the override students for a particular user for many objects at once, instead of doing separate queries for each
|
||||
quizzes, assignments = items.partition{|i| i.is_a?(Quizzes::Quiz)}
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(assignments, [:quiz, :assignment_overrides]).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(assignments, [:quiz, :assignment_overrides])
|
||||
|
||||
if assignments.any?
|
||||
override_students = AssignmentOverrideStudent.where(:assignment_id => assignments, :user_id => user).index_by(&:assignment_id)
|
||||
|
@ -349,7 +349,7 @@ module AssignmentOverrideApplicator
|
|||
end
|
||||
quizzes.uniq!
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(quizzes, :assignment_overrides).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(quizzes, :assignment_overrides)
|
||||
|
||||
if quizzes.any?
|
||||
override_students = AssignmentOverrideStudent.where(:quiz_id => quizzes, :user_id => user).index_by(&:quiz_id)
|
||||
|
|
|
@ -31,12 +31,12 @@ class EnrollmentDateBuilder
|
|||
def self.preload(enrollments)
|
||||
return if enrollments.empty?
|
||||
courses_loaded = enrollments.first.association(:course).loaded?
|
||||
ActiveRecord::Associations::Preloader.new(enrollments, :course).run unless courses_loaded
|
||||
ActiveRecord::Associations::Preloader.new.preload(enrollments, :course)unless courses_loaded
|
||||
|
||||
to_preload = enrollments.reject { |e| fetch(e) }
|
||||
return if to_preload.empty?
|
||||
ActiveRecord::Associations::Preloader.new(to_preload, :course_section).run
|
||||
ActiveRecord::Associations::Preloader.new(to_preload.map(&:course).uniq, :enrollment_term).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(to_preload, :course_section)
|
||||
ActiveRecord::Associations::Preloader.new.preload(to_preload.map(&:course).uniq, :enrollment_term)
|
||||
to_preload.each { |e| build(e) }
|
||||
end
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ module Outcomes
|
|||
#
|
||||
# Returns an Array of Rollup objects.
|
||||
def outcome_results_rollups(results, users=[])
|
||||
ActiveRecord::Associations::Preloader.new(results, :learning_outcome).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(results, :learning_outcome)
|
||||
rollups = results.chunk(&:user_id).map do |_, user_results|
|
||||
Rollup.new(user_results.first.user, rollup_user_results(user_results))
|
||||
end
|
||||
|
|
|
@ -1132,7 +1132,7 @@ describe ContextModule do
|
|||
end
|
||||
it "should not reload the tags if already loaded" do
|
||||
ContentTag.expects(:visible_to_students_in_course_with_da).never
|
||||
ActiveRecord::Associations::Preloader.new(@module, content_tags: :content).run
|
||||
ActiveRecord::Associations::Preloader.new.preload(@module, content_tags: :content)
|
||||
@module.content_tags_visible_to(@student_1)
|
||||
end
|
||||
it "should filter differentiated discussions" do
|
||||
|
|
Loading…
Reference in New Issue