improve accounts#settings page load time

set up a relation that can be loaded once, instead of applying the
same scope dozens of times

test plan: quick regression on account report term settings

refs CNVS-24764

Change-Id: I0cbbe96e712087834d68888b39893e9106e80282
Reviewed-on: https://gerrit.instructure.com/66401
Reviewed-by: James Williams  <jamesw@instructure.com>
Tested-by: Jenkins
QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2015-11-03 12:40:54 -07:00
parent 1ec23b8121
commit 65f4dbd7d4
2 changed files with 2 additions and 1 deletions

View File

@ -55,6 +55,7 @@ class Account < ActiveRecord::Base
has_many :all_groups, :class_name => 'Group', :foreign_key => 'root_account_id'
has_many :all_group_memberships, source: 'group_memberships', through: :all_groups
has_many :enrollment_terms, :foreign_key => 'root_account_id'
has_many :active_enrollment_terms, :class_name => 'EnrollmentTerm', :foreign_key => 'root_account_id', :conditions => ["enrollment_terms.workflow_state<>'deleted'"]
has_many :enrollments, :foreign_key => 'root_account_id', :conditions => ["enrollments.type != 'StudentViewEnrollment'"]
has_many :all_enrollments, :class_name => 'Enrollment', :foreign_key => 'root_account_id'
has_many :sub_accounts, :class_name => 'Account', :foreign_key => 'parent_account_id', :conditions => ['workflow_state != ?', 'deleted']

View File

@ -5,7 +5,7 @@
<% if all_terms_option %>
<option value="" <%= 'selected' unless @term %>><%= t(:all_terms, "All Terms") %></option>
<%end%>
<% @root_account.enrollment_terms.active.each do |term| %>
<% @root_account.active_enrollment_terms.each do |term| %>
<option value="<%= term.id %>" <%= 'selected' if term == @term %>><%= term.name %></option>
<% end %>
</select>