use preload/eager_load instead of includes
refs CNVS-21901 Change-Id: Ie9e1b2778b72f649392d8a1c47c0c86dae0ef19c Reviewed-on: https://gerrit.instructure.com/58660 Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
8a6819e85d
commit
56ccea56d4
|
@ -546,7 +546,8 @@ class AssignmentsApiController < ApplicationController
|
|||
def index
|
||||
if authorized_action(@context, @current_user, :read)
|
||||
scope = Assignments::ScopedToUser.new(@context, @current_user).scope.
|
||||
includes(:assignment_group, :rubric_association, :rubric).
|
||||
eager_load(:assignment_group).
|
||||
preload(:rubric_association, :rubric).
|
||||
reorder("assignment_groups.position, assignments.position")
|
||||
scope = Assignment.search_by_attribute(scope, :title, params[:search_term])
|
||||
da_enabled = @context.feature_enabled?(:differentiated_assignments)
|
||||
|
|
|
@ -195,7 +195,7 @@ class CollaborationsController < ApplicationController
|
|||
# @returns [Collaborator]
|
||||
def members
|
||||
return unless authorized_action(@collaboration, @current_user, :read)
|
||||
collaborators = @collaboration.collaborators.includes(:group, :user)
|
||||
collaborators = @collaboration.collaborators.preload(:group, :user)
|
||||
collaborators = Api.paginate(collaborators,
|
||||
self,
|
||||
api_v1_collaboration_members_url)
|
||||
|
|
|
@ -258,7 +258,7 @@ class ConversationsController < ApplicationController
|
|||
|
||||
if hash[:NOTES_ENABLED] && !hash[:CAN_ADD_NOTES_FOR_ACCOUNT]
|
||||
course_note_permissions = {}
|
||||
@current_user.enrollments.active.of_instructor_type.includes(:course).each do |enrollment|
|
||||
@current_user.enrollments.active.of_instructor_type.preload(:course).each do |enrollment|
|
||||
course_note_permissions[enrollment.course_id] = true if enrollment.has_permission_to?(:manage_user_notes)
|
||||
end
|
||||
hash[:CAN_ADD_NOTES_FOR_COURSES] = course_note_permissions
|
||||
|
@ -373,7 +373,7 @@ class ConversationsController < ApplicationController
|
|||
end
|
||||
|
||||
# reload and preload stuff
|
||||
conversations = ConversationParticipant.where(:id => batch.conversations).includes(:conversation).order("visible_last_authored_at DESC, last_message_at DESC, id DESC")
|
||||
conversations = ConversationParticipant.where(:id => batch.conversations).preload(:conversation).order("visible_last_authored_at DESC, last_message_at DESC, id DESC")
|
||||
Conversation.preload_participants(conversations.map(&:conversation))
|
||||
ConversationParticipant.preload_latest_messages(conversations, @current_user)
|
||||
visibility_map = infer_visibility(conversations)
|
||||
|
|
|
@ -402,7 +402,7 @@ class CoursesController < ApplicationController
|
|||
conditions = states.map{ |state|
|
||||
Enrollment::QueryBuilder.new(nil, course_workflow_state: state, enforce_course_workflow_state: true).conditions
|
||||
}.compact.join(" OR ")
|
||||
enrollments = @current_user.enrollments.joins(:course).includes(:course).where(conditions).shard(@current_user)
|
||||
enrollments = @current_user.enrollments.eager_load(:course).where(conditions).shard(@current_user)
|
||||
else
|
||||
enrollments = @current_user.cached_current_enrollments(preload_courses: true)
|
||||
end
|
||||
|
|
|
@ -73,7 +73,7 @@ class ErrorsController < ApplicationController
|
|||
|
||||
def index
|
||||
params[:page] = params[:page].to_i > 0 ? params[:page].to_i : 1
|
||||
@reports = ErrorReport.includes(:user)
|
||||
@reports = ErrorReport.preload(:user)
|
||||
|
||||
@message = params[:message]
|
||||
if error_search_enabled? && @message.present?
|
||||
|
|
|
@ -183,7 +183,7 @@ class FilesController < ApplicationController
|
|||
else
|
||||
@current_attachments = @current_folder.visible_file_attachments.by_position_then_display_name
|
||||
end
|
||||
@current_attachments = @current_attachments.includes(:thumbnail, :media_object)
|
||||
@current_attachments = @current_attachments.preload(:thumbnail, :media_object)
|
||||
render :json => @current_attachments.map do |a|
|
||||
a.as_json({
|
||||
methods: [ :readable_size, :currently_locked, :thumbnail_url ],
|
||||
|
@ -206,7 +206,7 @@ class FilesController < ApplicationController
|
|||
|
||||
if @current_user
|
||||
file_structure[:collaborations] = @current_user.collaborations.for_context(@context).active.
|
||||
includes(:user, :users).order("created_at DESC").map{ |c|
|
||||
preload(:user, :users).order("created_at DESC").map{ |c|
|
||||
c.as_json(permissions: {user: @current_user}, methods: [:collaborator_ids])
|
||||
}
|
||||
end
|
||||
|
@ -265,8 +265,8 @@ class FilesController < ApplicationController
|
|||
params[:include] << 'user' if params[:sort] == 'user'
|
||||
|
||||
scope = Attachments::ScopedToUser.new(@context || @folder, @current_user).scope
|
||||
scope = scope.includes(:user) if params[:include].include?('user') && params[:sort] != 'user'
|
||||
scope = scope.includes(:usage_rights) if params[:include].include?('usage_rights')
|
||||
scope = scope.preload(:user) if params[:include].include?('user') && params[:sort] != 'user'
|
||||
scope = scope.preload(:usage_rights) if params[:include].include?('usage_rights')
|
||||
scope = Attachment.search_by_attribute(scope, :display_name, params[:search_term])
|
||||
|
||||
order_clause = case params[:sort]
|
||||
|
|
|
@ -607,7 +607,7 @@ class GradebooksController < ApplicationController
|
|||
|
||||
|
||||
def assignment_groups_json(opts={})
|
||||
@context.assignment_groups.active.includes(:published_assignments).map { |g|
|
||||
@context.assignment_groups.active.preload(:published_assignments).map { |g|
|
||||
assignment_group_json(g, @current_user, session, ['assignments'], {
|
||||
stringify_json_ids: opts[:stringify_json_ids] || stringify_json_ids?
|
||||
})
|
||||
|
|
|
@ -101,7 +101,7 @@ class GroupMembershipsController < ApplicationController
|
|||
only_states = ALLOWED_MEMBERSHIP_FILTER
|
||||
only_states = only_states & params[:filter_states] if params[:filter_states]
|
||||
scope = scope.where(:workflow_state => only_states)
|
||||
scope = scope.includes(:group => :root_account)
|
||||
scope = scope.preload(group: :root_account)
|
||||
|
||||
@memberships = Api.paginate(scope, self, memberships_route)
|
||||
render :json => @memberships.map{ |gm| group_membership_json(gm, @current_user, session) }
|
||||
|
|
|
@ -202,7 +202,7 @@ class GroupsController < ApplicationController
|
|||
format.html do
|
||||
groups_scope = groups_scope.by_name
|
||||
groups_scope = groups_scope.where(:context_type => params[:context_type]) if params[:context_type]
|
||||
groups_scope = groups_scope.includes(:group_category)
|
||||
groups_scope = groups_scope.preload(:group_category)
|
||||
|
||||
groups = groups_scope.shard(@current_user).to_a
|
||||
|
||||
|
@ -216,7 +216,7 @@ class GroupsController < ApplicationController
|
|||
@groups = ShardedBookmarkedCollection.build(Group::Bookmarker, groups_scope) do |scope|
|
||||
scope = scope.scoped
|
||||
scope = scope.where(:context_type => params[:context_type]) if params[:context_type]
|
||||
scope.includes(:group_category)
|
||||
scope.preload(:group_category)
|
||||
end
|
||||
@groups = Api.paginate(@groups, self, api_v1_current_user_groups_url)
|
||||
render :json => (@groups.map { |g| group_json(g, @current_user, session) })
|
||||
|
@ -240,7 +240,7 @@ class GroupsController < ApplicationController
|
|||
return unless authorized_action(@context, @current_user, :read_roster)
|
||||
@groups = all_groups = @context.groups.active
|
||||
.order(GroupCategory::Bookmarker.order_by, Group::Bookmarker.order_by)
|
||||
.includes(:group_category)
|
||||
.eager_load(:group_category)
|
||||
|
||||
unless api_request?
|
||||
if @context.is_a?(Account)
|
||||
|
|
|
@ -301,7 +301,7 @@ class OutcomeResultsController < ApplicationController
|
|||
private
|
||||
|
||||
def user_rollups(opts = {})
|
||||
@results = find_outcome_results(users: @users, context: @context, outcomes: @outcomes).includes(:user)
|
||||
@results = find_outcome_results(users: @users, context: @context, outcomes: @outcomes).preload(:user)
|
||||
outcome_results_rollups(@results, @users)
|
||||
end
|
||||
|
||||
|
@ -357,12 +357,12 @@ class OutcomeResultsController < ApplicationController
|
|||
end
|
||||
|
||||
def include_alignments
|
||||
alignments = ContentTag.where(id: @results.map(&:content_tag_id)).includes(:content).map(&:content).uniq
|
||||
alignments = ContentTag.where(id: @results.map(&:content_tag_id)).preload(:content).map(&:content).uniq
|
||||
outcome_results_include_alignments_json(alignments)
|
||||
end
|
||||
|
||||
def include_outcomes_alignments
|
||||
alignments = ContentTag.learning_outcome_alignments.not_deleted.where(learning_outcome_id: @outcomes).includes(:content).map(&:content).uniq
|
||||
alignments = ContentTag.learning_outcome_alignments.not_deleted.where(learning_outcome_id: @outcomes).preload(:content).map(&:content).uniq
|
||||
outcome_results_include_alignments_json(alignments)
|
||||
end
|
||||
|
||||
|
@ -408,7 +408,7 @@ class OutcomeResultsController < ApplicationController
|
|||
def require_outcomes
|
||||
@outcome_groups = @context.learning_outcome_groups
|
||||
outcome_group_ids = @outcome_groups.pluck(:id)
|
||||
@outcome_links = ContentTag.learning_outcome_links.active.where(associated_asset_id: outcome_group_ids).includes(:learning_outcome_content)
|
||||
@outcome_links = ContentTag.learning_outcome_links.active.where(associated_asset_id: outcome_group_ids).preload(:learning_outcome_content)
|
||||
reject! "can't filter by both outcome_ids and outcome_group_id" if params[:outcome_ids] && params[:outcome_group_id]
|
||||
if params[:outcome_ids]
|
||||
outcome_ids = Api.value_to_array(params[:outcome_ids]).map(&:to_i).uniq
|
||||
|
|
|
@ -127,7 +127,7 @@ class Quizzes::QuizAssignmentOverridesController < ApplicationController
|
|||
api_route = api_v1_course_quiz_assignment_overrides_url(@course)
|
||||
quiz_ids = (Array(params[:quiz_assignment_overrides])[0] || {})[:quiz_ids]
|
||||
|
||||
scope = @course.quizzes.active.includes([ :assignment ])
|
||||
scope = @course.quizzes.active.preload(:assignment)
|
||||
scope = scope.where(id: quiz_ids) if quiz_ids.present?
|
||||
scope = scope.available unless can_manage
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class Quizzes::QuizzesController < ApplicationController
|
|||
|
||||
can_manage = @context.grants_right?(@current_user, session, :manage_assignments)
|
||||
|
||||
scope = @context.quizzes.active.includes([ :assignment ])
|
||||
scope = @context.quizzes.active.preload(:assignment)
|
||||
|
||||
# students only get to see published quizzes, and they will fetch the
|
||||
# overrides later using the API:
|
||||
|
|
|
@ -319,8 +319,8 @@ class SubmissionsApiController < ApplicationController
|
|||
|
||||
if params[:grouped].present?
|
||||
scope = (@section || @context).all_student_enrollments.
|
||||
includes(:user).
|
||||
where('users.id' => student_ids)
|
||||
eager_load(:user).
|
||||
where("users.id" => student_ids)
|
||||
|
||||
submissions = if requested_assignment_ids.present?
|
||||
Submission.where(
|
||||
|
|
|
@ -169,7 +169,7 @@ class UsersController < ApplicationController
|
|||
add_crumb(@current_user.short_name, crumb_url)
|
||||
add_crumb(t('crumbs.grades', 'Grades'), grades_path)
|
||||
|
||||
current_active_enrollments = @user.enrollments.current.includes(:course).shard(@user).to_a
|
||||
current_active_enrollments = @user.enrollments.current.preload(:course).shard(@user).to_a
|
||||
|
||||
@presenter = GradesPresenter.new(current_active_enrollments)
|
||||
|
||||
|
@ -975,12 +975,16 @@ class UsersController < ApplicationController
|
|||
if authorized_action(@user, @current_user, :view_statistics)
|
||||
add_crumb(t('crumbs.profile', "%{user}'s profile", :user => @user.short_name), @user == @current_user ? user_profile_path(@current_user) : user_path(@user) )
|
||||
|
||||
@group_memberships = @user.current_group_memberships.includes(:group)
|
||||
@group_memberships = @user.current_group_memberships.preload(:group)
|
||||
|
||||
# course_section and enrollment term will only be used if the enrollment dates haven't been cached yet;
|
||||
# maybe should just look at the first enrollment and check if it's cached to decide if we should include
|
||||
# them here
|
||||
@enrollments = @user.enrollments.shard(@user).where("enrollments.workflow_state<>'deleted' AND courses.workflow_state<>'deleted'").includes({:course => { :enrollment_term => :enrollment_dates_overrides }}, :associated_user, :course_section).to_a
|
||||
@enrollments = @user.enrollments.
|
||||
shard(@user).
|
||||
where("enrollments.workflow_state<>'deleted' AND courses.workflow_state<>'deleted'").
|
||||
eager_load(:course).
|
||||
preload(:associated_user, :course_section, course: { enrollment_term: :enrollment_dates_overrides }).to_a
|
||||
|
||||
# restrict view for other users
|
||||
if @user != @current_user
|
||||
|
@ -1821,7 +1825,7 @@ class UsersController < ApplicationController
|
|||
|
||||
if params[:student_id]
|
||||
student = User.find(params[:student_id])
|
||||
enrollments = student.student_enrollments.active.includes(:course).shard(student).to_a
|
||||
enrollments = student.student_enrollments.active.preload(:course).shard(student).to_a
|
||||
enrollments.each do |enrollment|
|
||||
should_include = enrollment.course.user_has_been_instructor?(@teacher) &&
|
||||
enrollment.course.enrollments_visible_to(@teacher, :include_priors => true).where(id: enrollment).first &&
|
||||
|
@ -1951,7 +1955,7 @@ class UsersController < ApplicationController
|
|||
|
||||
# find all ungraded submissions in one query
|
||||
ungraded_submissions = course.submissions.
|
||||
includes(:assignment).
|
||||
preload(:assignment).
|
||||
where("user_id IN (?) AND #{Submission.needs_grading_conditions}", ids).
|
||||
except(:order).
|
||||
order(:submitted_at).to_a
|
||||
|
|
|
@ -895,7 +895,7 @@ class Account < ActiveRecord::Base
|
|||
raise "must be a root account" unless self.root_account?
|
||||
Shard.partition_by_shard([self, Account.site_admin].uniq) do |accounts|
|
||||
next unless user.associated_shards.include?(Shard.current)
|
||||
AccountUser.includes(:account).joins(:account).where("user_id=? AND (root_account_id IN (?) OR account_id IN (?))", user, accounts, accounts)
|
||||
AccountUser.eager_load(:account).where("user_id=? AND (root_account_id IN (?) OR account_id IN (?))", user, accounts, accounts)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -67,9 +67,9 @@ class AssessmentRequest < ActiveRecord::Base
|
|||
scope :for_assessee, lambda { |user_id| where(:user_id => user_id) }
|
||||
scope :for_assessor, lambda { |assessor_id| where(:assessor_id => assessor_id) }
|
||||
scope :for_asset, lambda { |asset_id| where(:asset_id => asset_id)}
|
||||
scope :for_assignment, lambda { |assignment_id| includes(:submission).where(:submissions => { :assignment_id => assignment_id})}
|
||||
scope :for_course, lambda { |course_id| includes(:submission).where(:submissions => { :context_code => "course_#{course_id}"})}
|
||||
scope :for_context_codes, lambda { |context_codes| includes(:submission).where(:submissions => { :context_code =>context_codes })}
|
||||
scope :for_assignment, lambda { |assignment_id| eager_load(:submission).where(:submissions => { :assignment_id => assignment_id})}
|
||||
scope :for_course, lambda { |course_id| eager_load(:submission).where(:submissions => { :context_code => "course_#{course_id}"})}
|
||||
scope :for_context_codes, lambda { |context_codes| eager_load(:submission).where(:submissions => { :context_code =>context_codes })}
|
||||
|
||||
scope :not_ignored_by, lambda { |user, purpose|
|
||||
where("NOT EXISTS (?)",
|
||||
|
|
|
@ -308,7 +308,7 @@ class Assignment < ActiveRecord::Base
|
|||
|
||||
def update_student_submissions
|
||||
graded_at = Time.zone.now
|
||||
submissions.graded.includes(:user).find_each do |s|
|
||||
submissions.graded.preload(:user).find_each do |s|
|
||||
if grading_type == 'pass_fail' && ['complete', 'pass'].include?(s.grade)
|
||||
s.score = points_possible
|
||||
end
|
||||
|
@ -1371,7 +1371,7 @@ class Assignment < ActiveRecord::Base
|
|||
|
||||
includes = [:versions, :quiz_submission]
|
||||
includes << (grading_role == :grader ? :submission_comments : :all_submission_comments)
|
||||
submissions = self.submissions.where(:user_id => students).includes(*includes)
|
||||
submissions = self.submissions.where(:user_id => students).preload(*includes)
|
||||
|
||||
res[:too_many_quiz_submissions] = too_many = too_many_qs_versions?(submissions)
|
||||
qs_versions = quiz_submission_versions(submissions, too_many)
|
||||
|
@ -1493,7 +1493,7 @@ class Assignment < ActiveRecord::Base
|
|||
# name. for non-group assignments this just returns all visible users
|
||||
def representatives(user)
|
||||
if grade_as_group?
|
||||
submissions = self.submissions.includes(:user).to_a
|
||||
submissions = self.submissions.preload(:user).to_a
|
||||
users_with_submissions = submissions.select(&:has_submission?).map(&:user)
|
||||
users_with_turnitin_data = if turnitin_enabled?
|
||||
submissions
|
||||
|
@ -1535,7 +1535,7 @@ class Assignment < ActiveRecord::Base
|
|||
|
||||
def groups_and_ungrouped(user)
|
||||
groups_and_users = group_category.
|
||||
groups.active.includes(:group_memberships => :user).
|
||||
groups.active.preload(group_memberships: :user).
|
||||
map { |g| [g.name, g.users] }
|
||||
users_in_group = groups_and_users.flat_map { |_,users| users }
|
||||
groupless_users = visible_students_for_speed_grader(user) - users_in_group
|
||||
|
@ -1727,14 +1727,14 @@ class Assignment < ActiveRecord::Base
|
|||
WHERE assignments.id = submissions.assignment_id
|
||||
AND submissions.grade IS NOT NULL) AS graded_count") }
|
||||
|
||||
scope :include_quiz_and_topic, -> { includes(:quiz, :discussion_topic) }
|
||||
scope :include_quiz_and_topic, -> { preload(:quiz, :discussion_topic) }
|
||||
|
||||
scope :no_graded_quizzes_or_topics, -> { where("submission_types NOT IN ('online_quiz', 'discussion_topic')") }
|
||||
|
||||
scope :with_submissions, -> { includes(:submissions) }
|
||||
scope :with_submissions, -> { preload(:submissions) }
|
||||
|
||||
scope :with_submissions_for_user, lambda { |user|
|
||||
includes(:submissions).where("submissions.user_id = ?", user.id)
|
||||
eager_load(:submissions).where("submissions.user_id = ?", user.id)
|
||||
}
|
||||
|
||||
scope :for_context_codes, lambda { |codes| where(:context_code => codes) }
|
||||
|
@ -1781,7 +1781,7 @@ class Assignment < ActiveRecord::Base
|
|||
# Return all assignments and their active overrides where either the
|
||||
# assignment or one of its overrides is due between start and ending.
|
||||
scope :due_between_with_overrides, lambda { |start, ending|
|
||||
includes(:assignment_overrides).
|
||||
eager_load(:assignment_overrides).
|
||||
where('assignments.due_at BETWEEN ? AND ?
|
||||
OR assignment_overrides.due_at_overridden AND
|
||||
assignment_overrides.due_at BETWEEN ? AND ?', start, ending, start, ending)
|
||||
|
|
|
@ -146,7 +146,7 @@ class AssignmentGroup < ActiveRecord::Base
|
|||
self.assignments.map{|a| a.points_possible || 0}.sum
|
||||
end
|
||||
|
||||
scope :include_active_assignments, -> { includes(:active_assignments) }
|
||||
scope :include_active_assignments, -> { preload(:active_assignments) }
|
||||
scope :active, -> { where("assignment_groups.workflow_state<>'deleted'") }
|
||||
scope :before, lambda { |date| where("assignment_groups.created_at<?", date) }
|
||||
scope :for_context_codes, lambda { |codes| active.where(:context_code => codes).order(:position) }
|
||||
|
|
|
@ -136,7 +136,7 @@ class AssignmentOverride < ActiveRecord::Base
|
|||
|
||||
def set
|
||||
if self.set_type == 'ADHOC'
|
||||
assignment_override_students.includes(:user).map(&:user)
|
||||
assignment_override_students.preload(:user).map(&:user)
|
||||
else
|
||||
super
|
||||
end
|
||||
|
|
|
@ -228,7 +228,7 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
when User
|
||||
where(:user_id => context)
|
||||
when Notification
|
||||
includes(:notification_policies).where(:notification_policies => { :notification_id => context })
|
||||
eager_load(:notification_policies).where(:notification_policies => { :notification_id => context })
|
||||
else
|
||||
scoped
|
||||
end
|
||||
|
@ -271,7 +271,7 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
order("#{self.rank_sql(rank_order, 'communication_channels.path_type')} ASC, communication_channels.position asc").to_a
|
||||
end
|
||||
|
||||
scope :include_policies, -> { includes(:notification_policies) }
|
||||
scope :include_policies, -> { preload(:notification_policies) }
|
||||
|
||||
scope :in_state, lambda { |state| where(:workflow_state => state.to_s) }
|
||||
scope :of_type, lambda { |type| where(:path_type => type) }
|
||||
|
@ -356,7 +356,7 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
merge_candidates = {}
|
||||
Shard.with_each_shard(shards) do
|
||||
scope = scope.shard(Shard.current)
|
||||
scope.where("user_id<>?", self.user_id).includes(:user).map(&:user).select do |u|
|
||||
scope.where("user_id<>?", self.user_id).preload(:user).map(&:user).select do |u|
|
||||
result = merge_candidates.fetch(u.global_id) do
|
||||
merge_candidates[u.global_id] = (u.all_active_pseudonyms.length != 0)
|
||||
end
|
||||
|
|
|
@ -491,7 +491,7 @@ class ContentTag < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.order_by_outcome_title
|
||||
includes(:learning_outcome_content).order(outcome_title_order_by_clause)
|
||||
eager_load(:learning_outcome_content).order(outcome_title_order_by_clause)
|
||||
end
|
||||
|
||||
def visible_to_user?(user, opts=nil)
|
||||
|
|
|
@ -101,7 +101,7 @@ class ContextModule < ActiveRecord::Base
|
|||
|
||||
def evaluate_all_progressions
|
||||
current_column = 'context_module_progressions.current'
|
||||
current_scope = context_module_progressions.where("#{current_column} IS NULL OR #{current_column} = ?", false).includes(:user)
|
||||
current_scope = context_module_progressions.where("#{current_column} IS NULL OR #{current_column} = ?", false).preload(:user)
|
||||
|
||||
current_scope.find_in_batches(batch_size: 100) do |progressions|
|
||||
cache_visibilities_for_students(progressions.map(&:user_id)) if differentiated_assignments_enabled?
|
||||
|
|
|
@ -59,7 +59,7 @@ class Conversation < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.find_all_private_conversations(user, other_users)
|
||||
user.all_conversations.includes(:conversation).where(:private_hash => other_users.map { |u| private_hash_for([user, u]) }).
|
||||
user.all_conversations.preload(:conversation).where(:private_hash => other_users.map { |u| private_hash_for([user, u]) }).
|
||||
map(&:conversation)
|
||||
end
|
||||
|
||||
|
|
|
@ -269,12 +269,12 @@ class Course < ActiveRecord::Base
|
|||
CalendarEvent.
|
||||
active.
|
||||
for_user_and_context_codes(user, [asset_string]).
|
||||
includes(:child_events).
|
||||
preload(:child_events).
|
||||
reject(&:hidden?) +
|
||||
AppointmentGroup.manageable_by(user, [asset_string]) +
|
||||
user.assignments_visible_in_course(self)
|
||||
else
|
||||
calendar_events.active.includes(:child_events).reject(&:hidden?) +
|
||||
calendar_events.active.preload(:child_events).reject(&:hidden?) +
|
||||
assignments.active
|
||||
end
|
||||
end
|
||||
|
@ -410,7 +410,7 @@ class Course < ActiveRecord::Base
|
|||
else
|
||||
course_ids = courses_or_course_ids
|
||||
courses = Course.where(:id => course_ids).
|
||||
includes(:course_sections => [:course, :nonxlist_course]).
|
||||
preload(:course_sections => [:course, :nonxlist_course]).
|
||||
select([:id, :account_id]).to_a
|
||||
end
|
||||
course_ids_to_update_user_account_associations = []
|
||||
|
@ -1207,7 +1207,7 @@ class Course < ActiveRecord::Base
|
|||
|
||||
def self.find_all_by_context_code(codes)
|
||||
ids = codes.map{|c| c.match(/\Acourse_(\d+)\z/)[1] rescue nil }.compact
|
||||
Course.where(:id => ids).includes(:current_enrollments).to_a
|
||||
Course.where(:id => ids).preload(:current_enrollments).to_a
|
||||
end
|
||||
|
||||
def end_at
|
||||
|
@ -1412,7 +1412,7 @@ class Course < ActiveRecord::Base
|
|||
# 'publish_final_grades'
|
||||
|
||||
self.recompute_student_scores_without_send_later(user_ids_to_publish)
|
||||
enrollments = self.student_enrollments.not_fake.includes(:user, :course_section).order_by_sortable_name
|
||||
enrollments = self.student_enrollments.not_fake.eager_load(:user).preload(:course_section).order_by_sortable_name
|
||||
enrollments = enrollments.where(user_id: user_ids_to_publish) if user_ids_to_publish
|
||||
|
||||
errors = []
|
||||
|
@ -1490,6 +1490,7 @@ class Course < ActiveRecord::Base
|
|||
update_all(:grade_publishing_status => 'error', :grade_publishing_message => "Timed out.")
|
||||
end
|
||||
|
||||
|
||||
def gradebook_to_csv_in_background(filename, user, options = {})
|
||||
progress = progresses.build(tag: 'gradebook_to_csv')
|
||||
progress.save!
|
||||
|
@ -2601,7 +2602,7 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def participating_users(user_ids)
|
||||
enrollments = self.enrollments.includes(:user).
|
||||
enrollments = self.enrollments.eager_load(:user).
|
||||
where(:enrollments => {:workflow_state => 'active'}, :users => {:id => user_ids})
|
||||
Canvas::Builders::EnrollmentDateBuilder.preload(enrollments)
|
||||
enrollments.select { |e| e.active? }.map(&:user).uniq
|
||||
|
@ -2735,7 +2736,7 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def re_send_invitations!
|
||||
self.enrollments.invited.except(:includes).includes(:user => :communication_channels).find_each do |e|
|
||||
self.enrollments.invited.except(:includes).preload(:user => :communication_channels).find_each do |e|
|
||||
e.re_send_confirmation! if e.invited?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -81,7 +81,7 @@ class DelayedNotification < ActiveRecord::Base
|
|||
lookups.each do |klass, ids|
|
||||
includes = []
|
||||
includes = [:user] if klass == CommunicationChannel
|
||||
res += klass.where(:id => ids).includes(includes).to_a rescue []
|
||||
res += klass.where(:id => ids).preload(includes).to_a rescue []
|
||||
end
|
||||
@to_list = res.uniq
|
||||
end
|
||||
|
|
|
@ -224,7 +224,7 @@ class Enrollment < ActiveRecord::Base
|
|||
where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => ['available', 'claimed'] }) }
|
||||
|
||||
scope :all_student, -> {
|
||||
includes(:course).
|
||||
eager_load(:course).
|
||||
where("(enrollments.type = 'StudentEnrollment'
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed')
|
||||
AND courses.workflow_state IN ('available', 'completed')) OR
|
||||
|
@ -331,7 +331,7 @@ class Enrollment < ActiveRecord::Base
|
|||
section = CourseSection.find(self.course_section_id_was)
|
||||
|
||||
# ok, consider groups the user is in from the abandoned section's course
|
||||
self.user.groups.includes(:group_category).where(
|
||||
self.user.groups.preload(:group_category).where(
|
||||
:context_type => 'Course', :context_id => section.course_id).each do |group|
|
||||
|
||||
# check group deletion criteria if either enrollment is not a deletion
|
||||
|
|
|
@ -47,7 +47,7 @@ class GroupMembership < ActiveRecord::Base
|
|||
|
||||
has_a_broadcast_policy
|
||||
|
||||
scope :include_user, -> { includes(:user) }
|
||||
scope :include_user, -> { preload(:user) }
|
||||
|
||||
scope :active, -> { where("group_memberships.workflow_state<>'deleted'") }
|
||||
scope :moderators, -> { where(:moderator => true) }
|
||||
|
|
|
@ -216,7 +216,7 @@ class LearningOutcomeGroup < ActiveRecord::Base
|
|||
transaction do
|
||||
# delete the children of the group, both links and subgroups, then delete
|
||||
# the group itself
|
||||
self.child_outcome_links.active.includes(:content).each do |outcome_link|
|
||||
self.child_outcome_links.active.preload(:content).each do |outcome_link|
|
||||
outcome_link.skip_touch = true if @skip_tag_touch
|
||||
outcome_link.destroy
|
||||
end
|
||||
|
|
|
@ -115,7 +115,7 @@ class NotificationPolicy < ActiveRecord::Base
|
|||
end
|
||||
# Load and return user's policies after defaults may or may not have been set.
|
||||
# TODO: Don't load policies for retired channels
|
||||
NotificationPolicy.includes(:notification).for(user)
|
||||
NotificationPolicy.preload(:notification).for(user)
|
||||
end
|
||||
|
||||
# Updates notification policies for a given category in a given communication channel
|
||||
|
|
|
@ -37,7 +37,7 @@ module Polling
|
|||
can :create
|
||||
|
||||
given do |user, http_session|
|
||||
self.poll_sessions.shard(self).includes(:course).any? do |session|
|
||||
self.poll_sessions.shard(self).preload(:course).any? do |session|
|
||||
session.course.grants_right?(user, http_session, :manage_content)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -489,7 +489,7 @@ class Pseudonym < ActiveRecord::Base
|
|||
active.
|
||||
by_unique_id(credentials[:unique_id]).
|
||||
where(:account_id => account_ids).
|
||||
includes(:user).
|
||||
preload(:user).
|
||||
select { |p|
|
||||
valid = p.valid_arbitrary_credentials?(credentials[:password])
|
||||
too_many_attempts = true if p.audit_login(remote_ip, valid) == :too_many_attempts
|
||||
|
|
|
@ -25,7 +25,7 @@ module Quizzes::LogAuditing
|
|||
|
||||
snapshots = ::Quizzes::QuizSubmissionSnapshot.
|
||||
where({ quiz_submission_id: quiz_submission_ids }).
|
||||
includes(:quiz_submission)
|
||||
preload(:quiz_submission)
|
||||
|
||||
events_from_snapshots(snapshots)
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ module Quizzes
|
|||
|
||||
def self.grade_by_course(course)
|
||||
Quizzes::QuizSubmission.where('quizzes.context_id =?', course.id)
|
||||
.includes(:quiz)
|
||||
.eager_load(:quiz)
|
||||
.needs_grading
|
||||
.each do |quiz_submission|
|
||||
Quizzes::SubmissionGrader.new(quiz_submission).grade_submission({
|
||||
|
@ -56,7 +56,7 @@ module Quizzes
|
|||
outstanding_qs = []
|
||||
outstanding_qs = Quizzes::QuizSubmission.where("quiz_id = ?", @quiz.id)
|
||||
.needs_grading
|
||||
.includes(:user)
|
||||
.preload(:user)
|
||||
outstanding_qs
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1035,7 +1035,7 @@ class Quizzes::Quiz < ActiveRecord::Base
|
|||
can :view_answer_audits
|
||||
end
|
||||
|
||||
scope :include_assignment, -> { includes(:assignment) }
|
||||
scope :include_assignment, -> { preload(:assignment) }
|
||||
scope :before, lambda { |date| where("quizzes.created_at<?", date) }
|
||||
scope :active, -> { where("quizzes.workflow_state<>'deleted'") }
|
||||
scope :not_for_assignment, -> { where(:assignment_id => nil) }
|
||||
|
@ -1210,7 +1210,8 @@ class Quizzes::Quiz < ActiveRecord::Base
|
|||
def current_regrade
|
||||
Quizzes::QuizRegrade.where(quiz_id: id, quiz_version: version_number).
|
||||
where("quiz_question_regrades.regrade_option != 'disabled'").
|
||||
includes(:quiz_question_regrades => :quiz_question).first
|
||||
eager_load(:quiz_question_regrades).
|
||||
preload(quiz_question_regrades: :quiz_question).first
|
||||
end
|
||||
|
||||
def current_quiz_question_regrades
|
||||
|
@ -1220,7 +1221,7 @@ class Quizzes::Quiz < ActiveRecord::Base
|
|||
def questions_regraded_since(created_at)
|
||||
question_regrades = Set.new
|
||||
quiz_regrades.where("quiz_regrades.created_at > ? AND quiz_question_regrades.regrade_option != 'disabled'", created_at)
|
||||
.includes(:quiz_question_regrades).each do |regrade|
|
||||
.eager_load(:quiz_question_regrades).each do |regrade|
|
||||
ids = regrade.quiz_question_regrades.map { |qqr| qqr.quiz_question_id }
|
||||
question_regrades.merge(ids)
|
||||
end
|
||||
|
|
|
@ -250,7 +250,7 @@ class Quizzes::QuizQuestion < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.batch_migrate_file_links(ids)
|
||||
questions = Quizzes::QuizQuestion.includes(:quiz, :assessment_question).where(:id => ids)
|
||||
questions = Quizzes::QuizQuestion.preload(:quiz, :assessment_question).where(:id => ids)
|
||||
questions.each do |question|
|
||||
if question.migrate_file_links
|
||||
question.save
|
||||
|
|
|
@ -119,7 +119,7 @@ module Quizzes::QuizQuestionLinkMigrator
|
|||
def self.migrate_file_links_in_question_data(question_data, context={})
|
||||
return unless question_data
|
||||
changed = false
|
||||
question = context[:question] || Quizzes::QuizQuestion.includes(:quiz, :assessment_question).where(id: question_data[:id]).first
|
||||
question = context[:question] || Quizzes::QuizQuestion.where(id: question_data[:id]).first
|
||||
return unless question
|
||||
quiz = context[:quiz] || question.quiz
|
||||
for_each_interesting_field(question_data) do |field|
|
||||
|
|
|
@ -322,7 +322,7 @@ class Quizzes::QuizStatistics::StudentAnalysis < Quizzes::QuizStatistics::Report
|
|||
end
|
||||
|
||||
def prep_submissions(submissions)
|
||||
subs = submissions.includes(:versions).map do |qs|
|
||||
subs = submissions.preload(:versions).map do |qs|
|
||||
includes_all_versions? ? qs.attempts.version_models : qs.attempts.kept
|
||||
end
|
||||
subs = subs.flatten.compact.select do |s|
|
||||
|
|
|
@ -115,7 +115,7 @@ module Quizzes
|
|||
return questions, ContentTag.learning_outcome_alignments.active.where(
|
||||
:content_type => 'AssessmentQuestionBank',
|
||||
:content_id => bank_ids).
|
||||
includes(:learning_outcome, :context).to_a
|
||||
preload(:learning_outcome, :context).to_a
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,7 +86,7 @@ class RubricAssociation < ActiveRecord::Base
|
|||
scope :for_purpose, lambda { |purpose| where(:purpose => purpose) }
|
||||
scope :for_grading, -> { where(:purpose => 'grading') }
|
||||
scope :for_context_codes, lambda { |codes| where(:context_code => codes) }
|
||||
scope :include_rubric, -> { includes(:rubric) }
|
||||
scope :include_rubric, -> { preload(:rubric) }
|
||||
scope :before, lambda { |date| where("rubric_associations.created_at<?", date) }
|
||||
|
||||
def assert_uniqueness
|
||||
|
|
|
@ -351,7 +351,7 @@ class StreamItem < ActiveRecord::Base
|
|||
scope = where("updated_at<?", before_date).
|
||||
preload(:context).
|
||||
limit(1000)
|
||||
scope = scope.includes(:stream_item_instances) if touch_users
|
||||
scope = scope.preload(:stream_item_instances) if touch_users
|
||||
|
||||
while true
|
||||
batch = scope.reload.to_a
|
||||
|
|
|
@ -82,7 +82,7 @@ class Submission < ActiveRecord::Base
|
|||
validates_length_of :published_grade, :maximum => maximum_string_length, :allow_nil => true, :allow_blank => true
|
||||
validates_as_url :url
|
||||
|
||||
scope :with_comments, -> { includes(:submission_comments) }
|
||||
scope :with_comments, -> { preload(:submission_comments) }
|
||||
scope :after, lambda { |date| where("submissions.created_at>?", date) }
|
||||
scope :before, lambda { |date| where("submissions.created_at<?", date) }
|
||||
scope :submitted_before, lambda { |date| where("submitted_at<?", date) }
|
||||
|
@ -547,7 +547,7 @@ class Submission < ActiveRecord::Base
|
|||
|
||||
def submit_attachments_to_canvadocs
|
||||
if attachment_ids_changed?
|
||||
attachments.includes(:crocodoc_document).each do |a|
|
||||
attachments.preload(:crocodoc_document).each do |a|
|
||||
if Canvas::Crocodoc.enabled? && a.crocodocable?
|
||||
# indicates a crocodoc preview is coming
|
||||
a.crocodoc_document || a.create_crocodoc_document
|
||||
|
@ -703,7 +703,7 @@ class Submission < ActiveRecord::Base
|
|||
attachments_by_id = {}
|
||||
else
|
||||
attachments_by_id = Attachment.where(:id => bulk_attachment_ids)
|
||||
.includes(:thumbnail, :media_object)
|
||||
.preload(:thumbnail, :media_object)
|
||||
.group_by(&:id)
|
||||
end
|
||||
|
||||
|
@ -824,19 +824,19 @@ class Submission < ActiveRecord::Base
|
|||
|
||||
scope :graded, -> { where("submissions.grade IS NOT NULL") }
|
||||
|
||||
scope :ungraded, -> { where(:grade => nil).includes(:assignment) }
|
||||
scope :ungraded, -> { where(:grade => nil).preload(:assignment) }
|
||||
|
||||
scope :in_workflow_state, lambda { |provided_state| where(:workflow_state => provided_state) }
|
||||
|
||||
scope :having_submission, -> { where("submissions.submission_type IS NOT NULL") }
|
||||
scope :without_submission, -> { where(submission_type: nil, workflow_state: "unsubmitted") }
|
||||
|
||||
scope :include_user, -> { includes(:user) }
|
||||
scope :include_user, -> { preload(:user) }
|
||||
|
||||
scope :include_assessment_requests, -> { includes(:assessment_requests, :assigned_assessments) }
|
||||
scope :include_versions, -> { includes(:versions) }
|
||||
scope :include_submission_comments, -> { includes(:submission_comments) }
|
||||
scope :speed_grader_includes, -> { includes(:versions, :submission_comments, :attachments, :rubric_assessment) }
|
||||
scope :include_assessment_requests, -> { preload(:assessment_requests, :assigned_assessments) }
|
||||
scope :include_versions, -> { preload(:versions) }
|
||||
scope :include_submission_comments, -> { preload(:submission_comments) }
|
||||
scope :speed_grader_includes, -> { preload(:versions, :submission_comments, :attachments, :rubric_assessment) }
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
scope :needing_screenshot, -> { where("submissions.submission_type='online_url' AND submissions.attachment_id IS NULL AND submissions.process_attempts<3").order(:updated_at) }
|
||||
|
||||
|
|
|
@ -172,12 +172,12 @@ class User < ActiveRecord::Base
|
|||
|
||||
scope :of_account, lambda { |account| where("EXISTS (?)", account.user_account_associations.where("user_account_associations.user_id=users.id")).shard(account.shard) }
|
||||
scope :recently_logged_in, -> {
|
||||
includes(:pseudonyms).
|
||||
eager_load(:pseudonyms).
|
||||
where("pseudonyms.current_login_at>?", 1.month.ago).
|
||||
order("pseudonyms.current_login_at DESC").
|
||||
limit(25)
|
||||
}
|
||||
scope :include_pseudonym, -> { includes(:pseudonym) }
|
||||
scope :include_pseudonym, -> { preload(:pseudonym) }
|
||||
scope :restrict_to_sections, lambda { |sections|
|
||||
if sections.empty?
|
||||
scoped
|
||||
|
@ -601,7 +601,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
scope :with_service, lambda { |service|
|
||||
service = service.service if service.is_a?(UserService)
|
||||
includes(:user_services).where(:user_services => { :service => service.to_s })
|
||||
eager_load(:user_services).where(:user_services => { :service => service.to_s })
|
||||
}
|
||||
scope :enrolled_before, lambda { |date| where("enrollments.created_at<?", date) }
|
||||
|
||||
|
@ -2001,7 +2001,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
# :manage_groups is only available for admin enrollments
|
||||
admin_enrolls = self.enrollments.current.of_admin_type
|
||||
group_admin_courses = self.courses_for_enrollments(admin_enrolls).includes(:active_groups).select do |c|
|
||||
group_admin_courses = self.courses_for_enrollments(admin_enrolls).preload(:active_groups).select do |c|
|
||||
c.active_groups.any? && c.grants_right?(self, :manage_groups)
|
||||
end
|
||||
group_admin_courses.each do |c|
|
||||
|
@ -2560,7 +2560,7 @@ class User < ActiveRecord::Base
|
|||
# mfa settings for a user are the most restrictive of any pseudonyms the user has
|
||||
# a login for
|
||||
def mfa_settings
|
||||
result = self.pseudonyms.shard(self).includes(:account).map(&:account).uniq.map do |account|
|
||||
result = self.pseudonyms.shard(self).preload(:account).map(&:account).uniq.map do |account|
|
||||
case account.mfa_settings
|
||||
when :disabled
|
||||
0
|
||||
|
|
|
@ -134,7 +134,7 @@ class GradeSummaryPresenter
|
|||
def submissions
|
||||
@submissions ||= begin
|
||||
ss = @context.submissions
|
||||
.includes(:visible_submission_comments,
|
||||
.preload(:visible_submission_comments,
|
||||
{:rubric_assessments => [:rubric, :rubric_association]},
|
||||
:content_participations)
|
||||
.where("assignments.workflow_state != 'deleted'")
|
||||
|
|
|
@ -6,7 +6,7 @@ class AddContextModuleProgressionsUniqueIndex < ActiveRecord::Migration
|
|||
ContextModuleProgression.
|
||||
select([:user_id, :context_module_id]).
|
||||
group(:user_id, :context_module_id).
|
||||
includes(:context_module, :user).
|
||||
preload(:context_module, :user).
|
||||
where("user_id IS NOT NULL AND context_module_id IS NOT NULL").
|
||||
having("COUNT(*) > 1").find_each do |cmp|
|
||||
scope = ContextModuleProgression.
|
||||
|
|
|
@ -259,7 +259,7 @@ module AccountReports
|
|||
end
|
||||
|
||||
csv << headers
|
||||
courses = root_account.all_courses.includes(:account, :enrollment_term)
|
||||
courses = root_account.all_courses.preload(:account, :enrollment_term)
|
||||
courses = courses.where("courses.sis_source_id IS NOT NULL") if @sis_format
|
||||
|
||||
if @include_deleted
|
||||
|
|
|
@ -116,8 +116,8 @@ module Api::V1::StreamItem
|
|||
|
||||
def api_render_stream(opts)
|
||||
items = @current_user.shard.activate do
|
||||
scope = @current_user.visible_stream_item_instances(opts).includes(:stream_item)
|
||||
scope = scope.joins(:stream_item).where("stream_items.asset_type=?", opts[:asset_type]) if opts.has_key?(:asset_type)
|
||||
scope = @current_user.visible_stream_item_instances(opts).preload(:stream_item)
|
||||
scope = scope.eager_load(:stream_item).where("stream_items.asset_type=?", opts[:asset_type]) if opts.has_key?(:asset_type)
|
||||
if opts.has_key?(:submission_user_id) || opts[:asset_type] == 'Submission'
|
||||
scope = scope.joins("INNER JOIN #{Submission.quoted_table_name} ON submissions.id=asset_id")
|
||||
# just because there are comments doesn't mean the user can see them.
|
||||
|
|
|
@ -316,7 +316,7 @@ module Canvas::Migration::Helpers
|
|||
end
|
||||
|
||||
def course_assignment_data(content_list, source_course)
|
||||
source_course.assignment_groups.active.includes(:assignments).select("id, name").each do |group|
|
||||
source_course.assignment_groups.active.preload(:assignments).select("id, name").each do |group|
|
||||
item = course_item_hash('assignment_groups', group)
|
||||
content_list << item
|
||||
group.assignments.active.select(:id).select(:title).each do |asmnt|
|
||||
|
@ -327,7 +327,7 @@ module Canvas::Migration::Helpers
|
|||
end
|
||||
|
||||
def course_attachments_data(content_list, source_course)
|
||||
Canvas::ICU.collate_by(source_course.folders.active.select('id, full_name, name').includes(:active_file_attachments), &:full_name).each do |folder|
|
||||
Canvas::ICU.collate_by(source_course.folders.active.select('id, full_name, name').preload(:active_file_attachments), &:full_name).each do |folder|
|
||||
next if folder.active_file_attachments.length == 0
|
||||
|
||||
item = course_item_hash('folders', folder)
|
||||
|
|
|
@ -2,12 +2,12 @@ module DataFixup::ExcludeDeletedEntriesFromUnreadCount
|
|||
def self.run
|
||||
# Deleted all partipant entries for deleted discussion entries
|
||||
DiscussionEntryParticipant.
|
||||
includes(:discussion_entry).
|
||||
eager_load(:discussion_entry).
|
||||
where(:discussion_entries => { :workflow_state => 'deleted' }).
|
||||
destroy_all
|
||||
|
||||
# Recalculate counts based on active entries minus read entries
|
||||
DiscussionTopicParticipant.includes(:discussion_topic).find_each do |participant|
|
||||
DiscussionTopicParticipant.preload(:discussion_topic).find_each do |participant|
|
||||
topic = participant.discussion_topic
|
||||
read_count = topic.discussion_entry_participants.where(:user_id => participant.user_id, :workflow_state => "read").count
|
||||
participant.unread_entry_count = topic.discussion_entries.active.count - read_count
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module DataFixup::FixBulkMessageAttachments
|
||||
def self.run
|
||||
ConversationBatch.includes(:root_conversation_message).find_each do |batch|
|
||||
ConversationBatch.preload(:root_conversation_message).find_each do |batch|
|
||||
root_message = batch.root_conversation_message
|
||||
next unless root_message.has_attachments?
|
||||
messages = ConversationMessage.find(batch.conversation_message_ids)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module DataFixup::FixInvalidCourseIdsOnEnrollments
|
||||
def self.run
|
||||
Enrollment.joins(:course_section).
|
||||
Enrollment.joins(:course_section).eager_load(:course_section).
|
||||
where("course_sections.course_id<>enrollments.course_id").
|
||||
includes(:course_section).find_each do |e|
|
||||
find_each do |e|
|
||||
Enrollment.where(id: e).update_all(course_id: e.course_section.course_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module DataFixup::FixInvalidPseudonymAccountIds
|
||||
def self.run
|
||||
Pseudonym.where("NOT EXISTS (?)", Account.where("account_id=accounts.id AND root_account_id IS NULL")).
|
||||
includes(:account, :user).find_each do |p|
|
||||
preload(:account, :user).find_each do |p|
|
||||
if p.workflow_state == 'deleted'
|
||||
destroy_pseudonym(p)
|
||||
elsif Pseudonym.where(account_id: p.root_account_id, sis_user_id: p.sis_user_id).
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module DataFixup::MoveScribdDocsToRootAttachments
|
||||
def self.run
|
||||
Shackles.activate(:slave) do
|
||||
Attachment.where("scribd_doc IS NOT NULL AND root_attachment_id IS NOT NULL").includes(:root_attachment).find_each do |a|
|
||||
Attachment.where("scribd_doc IS NOT NULL AND root_attachment_id IS NOT NULL").preload(:root_attachment).find_each do |a|
|
||||
ra = a.root_attachment
|
||||
# bad data!
|
||||
next unless ra
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module DataFixup::ReintroduceDeletedEntriesToUnreadCount
|
||||
def self.run
|
||||
# Recalculate counts to include deleted entries
|
||||
DiscussionTopicParticipant.includes(:discussion_topic, :user).find_each do |participant|
|
||||
DiscussionTopicParticipant.preload(:discussion_topic, :user).find_each do |participant|
|
||||
# since the previous code treated all deleted discussion entries as
|
||||
# hidden and not included in unread counts, we're going to update all
|
||||
# pre-existing deleted entries to be marked as read for all users
|
||||
|
|
|
@ -12,7 +12,7 @@ module DataFixup::RemoveDuplicateGroupDiscussions
|
|||
bad_root_topics.each do |context_id, context_type, root_topic_id|
|
||||
children = DiscussionTopic.
|
||||
where(:context_id => context_id, :context_type => context_type, :root_topic_id => root_topic_id).
|
||||
includes(:discussion_entries).
|
||||
preload(:discussion_entries).
|
||||
sort_by{ |dt| dt.discussion_entries.length }
|
||||
|
||||
# keep the active topic with the most entries
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace :canvas do
|
|||
model.transaction do
|
||||
snapshots = Quizzes::QuizSubmissionSnapshot.
|
||||
where(quiz_submission_id: quiz_submission_ids).
|
||||
includes(:quiz_submission).
|
||||
preload(:quiz_submission).
|
||||
reject { |snapshot| snapshot.quiz_submission.nil? }
|
||||
|
||||
puts "Generating #{snapshots.length} events..."
|
||||
|
|
|
@ -784,7 +784,7 @@ describe EnrollmentsApiController, type: :request do
|
|||
e.sis_batch_id = sis_batch.id
|
||||
e.save!
|
||||
json = api_call(:get, @user_path, @user_params)
|
||||
enrollments = @student.enrollments.current.includes(:user).order("users.sortable_name ASC")
|
||||
enrollments = @student.enrollments.current.eager_load(:user).order("users.sortable_name ASC")
|
||||
expect(json).to eq enrollments.map { |e|
|
||||
{
|
||||
'root_account_id' => e.root_account_id,
|
||||
|
@ -835,7 +835,7 @@ describe EnrollmentsApiController, type: :request do
|
|||
recent_activity.record!(Time.zone.now - 5.minutes)
|
||||
recent_activity.record!(Time.zone.now)
|
||||
json = api_call(:get, @user_path, @user_params)
|
||||
enrollments = @student.enrollments.current.includes(:user).order("users.sortable_name ASC")
|
||||
enrollments = @student.enrollments.current.eager_load(:user).order("users.sortable_name ASC")
|
||||
expect(json).to eq enrollments.map { |e|
|
||||
{
|
||||
'root_account_id' => e.root_account_id,
|
||||
|
@ -1018,7 +1018,7 @@ describe EnrollmentsApiController, type: :request do
|
|||
@user = current_user
|
||||
json = api_call(:get, @path, @params)
|
||||
enrollments = %w{observer student ta teacher}.inject([]) do |res, type|
|
||||
res + @course.send("#{type}_enrollments").includes(:user).order(User.sortable_name_order_by_clause("users"))
|
||||
res + @course.send("#{type}_enrollments").eager_load(:user).order(User.sortable_name_order_by_clause("users"))
|
||||
end
|
||||
expect(json).to eq enrollments.map { |e|
|
||||
h = {
|
||||
|
@ -1104,7 +1104,7 @@ describe EnrollmentsApiController, type: :request do
|
|||
|
||||
it "should list its own enrollments" do
|
||||
json = api_call(:get, @user_path, @user_params)
|
||||
enrollments = @user.enrollments.current.includes(:user).order("users.sortable_name ASC")
|
||||
enrollments = @user.enrollments.current.eager_load(:user).order("users.sortable_name ASC")
|
||||
expect(json).to eq enrollments.map { |e|
|
||||
{
|
||||
'root_account_id' => e.root_account_id,
|
||||
|
@ -1204,7 +1204,7 @@ describe EnrollmentsApiController, type: :request do
|
|||
it "should include users' sis and login ids" do
|
||||
json = api_call(:get, @path, @params)
|
||||
enrollments = %w{observer student ta teacher}.inject([]) do |res, type|
|
||||
res + @course.send("#{type}_enrollments").includes(:user)
|
||||
res + @course.send("#{type}_enrollments").preload(:user)
|
||||
end
|
||||
expect(json).to eq(enrollments.map do |e|
|
||||
user_json = {
|
||||
|
@ -1317,7 +1317,7 @@ describe EnrollmentsApiController, type: :request do
|
|||
it "should properly paginate" do
|
||||
json = api_call(:get, "#{@path}?page=1&per_page=1", @params.merge(:page => 1.to_param, :per_page => 1.to_param))
|
||||
enrollments = %w{observer student ta teacher}.inject([]) { |res, type|
|
||||
res = res + @course.send("#{type}_enrollments").includes(:user)
|
||||
res = res + @course.send("#{type}_enrollments").preload(:user)
|
||||
}.map do |e|
|
||||
h = {
|
||||
'root_account_id' => e.root_account_id,
|
||||
|
|
|
@ -823,7 +823,7 @@ describe Course, "enroll" do
|
|||
it "should scope correctly when including teachers from course" do
|
||||
account = @course.account
|
||||
@course.enroll_student(@user)
|
||||
scope = account.associated_courses.active.select([:id, :name]).joins(:teachers).includes(:teachers).where(:enrollments => { :workflow_state => 'active' })
|
||||
scope = account.associated_courses.active.select([:id, :name]).eager_load(:teachers).joins(:teachers).where(:enrollments => { :workflow_state => 'active' })
|
||||
sql = scope.to_sql
|
||||
expect(sql).to match(/enrollments.type = 'TeacherEnrollment'/)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue