Skip to content

Commit

Permalink
Some rails 7 tests passing
Browse files Browse the repository at this point in the history
Change-Id: Iad400936d7e53a5f92644f260c95bfb5bf9e972f
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/293144
QA-Review: Jacob Burroughs <[email protected]>
Product-Review: Jacob Burroughs <[email protected]>
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: August Thornton <[email protected]>
Reviewed-by: Alex Slaughter <[email protected]>
Migration-Review: Alex Slaughter <[email protected]>
  • Loading branch information
maths22 committed Jun 6, 2022
1 parent 1331651 commit 5dcd66d
Show file tree
Hide file tree
Showing 115 changed files with 258 additions and 240 deletions.
12 changes: 6 additions & 6 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def index
else
[]
end
ActiveRecord::Associations::Preloader.new.preload(@accounts, :root_account)
ActiveRecord::Associations.preload(@accounts, :root_account)

# originally had 'includes' instead of 'include' like other endpoints
includes = params[:include] || params[:includes]
Expand Down Expand Up @@ -377,7 +377,7 @@ def course_accounts
else
@accounts = []
end
ActiveRecord::Associations::Preloader.new.preload(@accounts, :root_account)
ActiveRecord::Associations.preload(@accounts, :root_account)
render json: @accounts.map { |a| account_json(a, @current_user, session, params[:includes] || [], true) }
end

Expand Down Expand Up @@ -483,7 +483,7 @@ def sub_accounts
@accounts = Api.paginate(@accounts, self, api_v1_sub_accounts_url,
total_entries: recursive ? nil : @accounts.count)

ActiveRecord::Associations::Preloader.new.preload(@accounts, [:root_account, :parent_account])
ActiveRecord::Associations.preload(@accounts, [:root_account, :parent_account])
render json: @accounts.map { |a| account_json(a, @current_user, session, []) }
end

Expand Down Expand Up @@ -760,10 +760,10 @@ def courses_api
GuardRail.activate(:secondary) do
@courses = Api.paginate(@courses, self, api_v1_account_courses_url, { total_entries: nil })

ActiveRecord::Associations::Preloader.new.preload(@courses, [:account, :root_account, course_account_associations: :account])
ActiveRecord::Associations.preload(@courses, [:account, :root_account, course_account_associations: :account])
preload_teachers(@courses) if includes.include?("teachers")
preload_teachers(@courses) if includes.include?("active_teachers")
ActiveRecord::Associations::Preloader.new.preload(@courses, [:enrollment_term]) if includes.include?("term") || includes.include?("concluded")
ActiveRecord::Associations.preload(@courses, [:enrollment_term]) if includes.include?("term") || includes.include?("concluded")

if includes.include?("total_students")
student_counts = StudentEnrollment.shard(@account.shard).not_fake.where("enrollments.workflow_state NOT IN ('rejected', 'completed', 'deleted', 'inactive')")
Expand Down Expand Up @@ -1193,7 +1193,7 @@ def settings
if authorized_action(@account, @current_user, :read_as_admin)
@account_users = @account.account_users.active
@account_user_permissions_cache = AccountUser.create_permissions_cache(@account_users, @current_user, session)
ActiveRecord::Associations::Preloader.new.preload(@account_users, user: :communication_channels)
ActiveRecord::Associations.preload(@account_users, user: :communication_channels)
order_hash = {}
@account.available_account_roles.each_with_index do |role, idx|
order_hash[role.id] = idx
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/appointment_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ def index
api_v1_appointment_groups_url(scope: params[:scope])
)
if params[:include]
ActiveRecord::Associations::Preloader.new.preload(groups,
[{ appointments: [:parent_event,
{ context: [{ appointment_group_contexts: :context },
:appointment_group_sub_contexts] },
{ child_events: [:parent_event,
:context,
{ child_events: [:parent_event,
:context] }] }] },
{ appointment_group_contexts: :context },
:appointment_group_sub_contexts])
ActiveRecord::Associations.preload(groups,
[{ appointments: [:parent_event,
{ context: [{ appointment_group_contexts: :context },
:appointment_group_sub_contexts] },
{ child_events: [:parent_event,
:context,
{ child_events: [:parent_event,
:context] }] }] },
{ appointment_group_contexts: :context },
:appointment_group_sub_contexts])
end
render json: groups.map { |group| appointment_group_json(group, @current_user, session, include: params[:include]) }
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/assignments_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def get_assignments(user)
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.preload(assignments, :assignment_overrides)
ActiveRecord::Associations.preload(assignments, :assignment_overrides)
assignments.select { |a| a.assignment_overrides.empty? }
.each { |a| a.has_no_overrides = true }

Expand Down Expand Up @@ -896,7 +896,7 @@ def get_assignments(user)
preloaded_attachments = api_bulk_load_user_content_attachments(assignments.map(&:description), @context)

if include_params.include?("score_statistics")
ActiveRecord::Associations::Preloader.new.preload(assignments, :score_statistic)
ActiveRecord::Associations.preload(assignments, :score_statistic)
end

mc_status = setup_master_course_restrictions(assignments, context)
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/calendar_events_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def render_events_for_user(user, route_url)
end

events = Api.paginate(scope, self, route_url)
ActiveRecord::Associations::Preloader.new.preload(events, :child_events) if @type == :event
ActiveRecord::Associations.preload(events, :child_events) if @type == :event
if @type == :assignment
events = apply_assignment_overrides(events, user)
mark_submitted_assignments(user, events)
Expand All @@ -395,7 +395,7 @@ def render_events_for_user(user, route_url)
.group_by(&:assignment_id)
end
# preload data used by assignment_json
ActiveRecord::Associations::Preloader.new.preload(events, :discussion_topic)
ActiveRecord::Associations.preload(events, :discussion_topic)
Shard.partition_by_shard(events) do |shard_events|
having_submission = Assignment.assignment_ids_with_submissions(shard_events.map(&:id))
shard_events.each do |event|
Expand All @@ -415,9 +415,9 @@ def render_events_for_user(user, route_url)

if @errors.empty?
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), %i[account grading_period_groups enrollment_term])
ActiveRecord::Associations.preload(calendar_events, [:context, :parent_event])
ActiveRecord::Associations.preload(assignments, Api::V1::Assignment::PRELOADS)
ActiveRecord::Associations.preload(assignments.map(&:context), %i[account grading_period_groups enrollment_term])

json = events.map do |event|
subs = submissions[event.id] if submissions
Expand Down Expand Up @@ -799,7 +799,7 @@ def public_feed
@contexts.each do |context|
log_asset_access(["calendar_feed", context], "calendar", "other", context: @context)
end
ActiveRecord::Associations::Preloader.new.preload(@events, :context)
ActiveRecord::Associations.preload(@events, :context)

respond_to do |format|
format.ics do
Expand Down Expand Up @@ -1258,15 +1258,15 @@ def search_params
end

def apply_assignment_overrides(events, user)
ActiveRecord::Associations::Preloader.new.preload(events, [:context, :assignment_overrides])
ActiveRecord::Associations.preload(events, [:context, :assignment_overrides])
events.each { |e| e.has_no_overrides = true if e.assignment_overrides.empty? }

if AssignmentOverrideApplicator.should_preload_override_students?(events, user, "calendar_events_api")
AssignmentOverrideApplicator.preload_assignment_override_students(events, user)
end

unless (params[:excludes] || []).include?("assignments")
ActiveRecord::Associations::Preloader.new.preload(events, [:rubric, :rubric_association])
ActiveRecord::Associations.preload(events, [:rubric, :rubric_association])
# improves locked_json performance

student_events = events.reject { |e| e.context.grants_right?(user, session, :read_as_admin) }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/context_module_items_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,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.preload(mod, content_tags: :content)
ActiveRecord::Associations.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])
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/context_modules_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def index
scope = ContextModule.search_by_attribute(scope, :name, params[:search_term]) unless includes.include?("items")
modules = Api.paginate(scope, self, route)

ActiveRecord::Associations::Preloader.new.preload(modules, content_tags: :content) if includes.include?("items")
ActiveRecord::Associations.preload(modules, content_tags: :content) if includes.include?("items")

modules_and_progressions = if @student
modules.map { |m| [m, m.evaluate_for(@student)] }
Expand Down Expand Up @@ -212,7 +212,7 @@ def show
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.preload(mod, content_tags: :content) if includes.include?("items")
ActiveRecord::Associations.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
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/context_modules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def content_tag_assignment_data
all_tags = GuardRail.activate(:secondary) { @context.module_items_visible_to(@current_user).to_a }
user_is_admin = @context.grants_right?(@current_user, session, :read_as_admin)

ActiveRecord::Associations::Preloader.new.preload(all_tags, :content)
ActiveRecord::Associations.preload(all_tags, :content)

preload_assignments_and_quizzes(all_tags, user_is_admin)

Expand Down Expand Up @@ -774,7 +774,7 @@ def preload_assignments_and_quizzes(tags, user_is_admin)

content_with_assignments = assignment_tags
.select { |ct| ct.content_type != "Assignment" && ct.content.assignment_id }.map(&:content)
ActiveRecord::Associations::Preloader.new.preload(content_with_assignments, :assignment) if content_with_assignments.any?
ActiveRecord::Associations.preload(content_with_assignments, :assignment) if content_with_assignments.any?

if user_is_admin && should_preload_override_data?
assignments = assignment_tags.filter_map(&:assignment)
Expand All @@ -785,7 +785,7 @@ def preload_assignments_and_quizzes(tags, user_is_admin)
overrideables = (assignments + plain_quizzes).reject(&:has_too_many_overrides)

if overrideables.any?
ActiveRecord::Associations::Preloader.new.preload(overrideables, :assignment_overrides)
ActiveRecord::Associations.preload(overrideables, :assignment_overrides)
overrideables.each { |o| o.has_no_overrides = true if o.assignment_overrides.empty? }
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def show
messages = nil
GuardRail.activate(:secondary) do
messages = @conversation.messages
ActiveRecord::Associations::Preloader.new.preload(messages, :asset)
ActiveRecord::Associations.preload(messages, :asset)
end

render json: conversation_json(@conversation,
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ def enroll_users
current_user: @current_user)
end
if !@context.concluded? && (@enrollments = EnrollmentsFromUserList.process(list, @context, enrollment_options))
ActiveRecord::Associations::Preloader.new.preload(@enrollments, [:course_section, { user: [:communication_channel, :pseudonym] }])
ActiveRecord::Associations.preload(@enrollments, [:course_section, { user: [:communication_channel, :pseudonym] }])
json = @enrollments.map do |e|
{ "enrollment" =>
{ "associated_user_id" => e.associated_user_id,
Expand Down Expand Up @@ -3766,7 +3766,7 @@ def courses_for_user(user, paginate_url: api_v1_courses_url)
enrollments = enrollments.to_a
elsif params[:enrollment_state] == "active"
enrollments = user.participating_enrollments
ActiveRecord::Associations::Preloader.new.preload(enrollments, :course)
ActiveRecord::Associations.preload(enrollments, :course)
else
enrollments = user.cached_currentish_enrollments(preload_courses: true)
end
Expand All @@ -3779,7 +3779,7 @@ def courses_for_user(user, paginate_url: api_v1_courses_url)

# we always output the role in the JSON, but we need it now in case we're
# running the condition below
ActiveRecord::Associations::Preloader.new.preload(enrollments, :role)
ActiveRecord::Associations.preload(enrollments, :role)
# these are all duplicated in the params[:state] block above in SQL. but if
# used the cached ones, or we added include_observed, we have to re-run them
# in pure ruby
Expand Down Expand Up @@ -3845,14 +3845,14 @@ def courses_for_user(user, paginate_url: api_v1_courses_url)
end
preloads << { context_modules: :content_tags } if includes.include?("course_progress")
preloads << :enrollment_term if includes.include?("term") || includes.include?("concluded")
ActiveRecord::Associations::Preloader.new.preload(courses, preloads)
ActiveRecord::Associations.preload(courses, preloads)
MasterCourses::MasterTemplate.preload_is_master_course(courses)

preloads = []
preloads << :course_section if includes.include?("sections")
preloads << { scores: :course } if includes.include?("total_scores") || includes.include?("current_grading_period_scores")

ActiveRecord::Associations::Preloader.new.preload(enrollments, preloads) unless preloads.empty?
ActiveRecord::Associations.preload(enrollments, preloads) unless preloads.empty?
if includes.include?("course_progress")
progressions = ContextModuleProgression.joins(:context_module).where(user: user, context_modules: { course: courses }).select("context_module_progressions.*, context_modules.context_id AS course_id").to_a.group_by { |cmp| cmp["course_id"] }
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/discussion_topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def index
if @context.is_a?(Group) || request.format.json?
@topics = Api.paginate(scope, self, topic_pagination_url)
if params[:exclude_context_module_locked_topics]
ActiveRecord::Associations::Preloader.new.preload(@topics, context_module_tags: :context_module)
ActiveRecord::Associations.preload(@topics, context_module_tags: :context_module)
@topics = DiscussionTopic.reject_context_module_locked_topics(@topics, @current_user)
end

Expand All @@ -379,7 +379,7 @@ def index
named_context_url(@context, :context_discussion_topics_url))

if @context.is_a?(Group)
ActiveRecord::Associations::Preloader.new.preload(@topics, context_module_tags: :context_module)
ActiveRecord::Associations.preload(@topics, context_module_tags: :context_module)
locked_topics, open_topics = @topics.partition do |topic|
locked = topic.locked? || topic.locked_for?(@current_user)
locked.is_a?(Hash) ? locked[:can_view] : locked
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/enrollments_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def index
self, send("api_v1_#{endpoint_scope}_enrollments_url")
)

ActiveRecord::Associations::Preloader.new.preload(enrollments, %i[user course course_section root_account sis_pseudonym])
ActiveRecord::Associations.preload(enrollments, %i[user course course_section root_account sis_pseudonym])

include_group_ids = Array(params[:include]).include?("group_ids")
includes = [:user] + Array(params[:include])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gradebook_history_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def feed
# paginate the indexed scope and then convert to actual Version records
path = api_v1_gradebook_history_feed_url(@context, params.permit(:course_id, :assignment_id, :user_id, :ascending, :format))
indexed_versions = Api.paginate(indexed_versions, self, path)
ActiveRecord::Associations::Preloader.new.preload(indexed_versions, :version)
ActiveRecord::Associations.preload(indexed_versions, :version)
versions = indexed_versions.filter_map(&:version)

render json: versions_json(@context, versions, api_context(nil), assignment: assignment, student: student)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/master_courses/master_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def unsynced_changes
def migrations_index
# sort id desc
migrations = Api.paginate(@template.master_migrations.order("id DESC"), self, api_v1_course_blueprint_migrations_url)
ActiveRecord::Associations::Preloader.new.preload(migrations, :user)
ActiveRecord::Associations.preload(migrations, :user)
render json: migrations.map { |migration| master_migration_json(migration, @current_user, session) }
end

Expand Down Expand Up @@ -598,7 +598,7 @@ def imports_index
.where(migration_type: "master_course_import", child_subscription_id: @subscription)
.order("id DESC")
migrations = Api.paginate(migrations, self, api_v1_course_blueprint_imports_url)
ActiveRecord::Associations::Preloader.new.preload(migrations, :user)
ActiveRecord::Associations.preload(migrations, :user)
render json: migrations.map { |migration|
master_migration_json(migration.master_migration, @current_user,
session, child_migration: migration,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/outcome_groups_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def outcomes
outcome_params[:context] = @context

# preload the links' outcomes' contexts.
ActiveRecord::Associations::Preloader.new.preload(@links, learning_outcome_content: :context)
ActiveRecord::Associations.preload(@links, learning_outcome_content: :context)

if context&.root_account&.feature_enabled?(:improved_outcomes_management) && Account.site_admin.feature_enabled?(:outcomes_friendly_description)
account = @context.is_a?(Account) ? @context : @context.account
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/outcome_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def filter_users_by_excludes(aggregate = false)
filters << "completed" if exclude_concluded
filters << "inactive" if exclude_inactive

ActiveRecord::Associations::Preloader.new.preload(@users, :enrollments)
ActiveRecord::Associations.preload(@users, :enrollments)
@users = @users.reject { |u| u.enrollments.all? { |e| filters.include? e.workflow_state } }
end

Expand Down Expand Up @@ -588,7 +588,7 @@ def require_outcomes
associations << { associated_asset: :learning_outcome_group }
end
@outcome_links.each_slice(100) do |outcome_links_slice|
ActiveRecord::Associations::Preloader.new.preload(outcome_links_slice, associations)
ActiveRecord::Associations.preload(outcome_links_slice, associations)
end
@outcomes = @outcome_links.map(&:learning_outcome_content)
end
Expand Down
Loading

0 comments on commit 5dcd66d

Please sign in to comment.