Optimize for_context queries for accounts
fixes OUT-4382 flag=none Replaced a join between content tags and a union of account and course content tags with a single union of account and course content tags. See blog link in the comments of the Jira issue above for more details. test plan: - confirm that viewing account outcome alignments, that both account-level and course-level alignments appear - this can be tested by creating an account outcome, aligning it to an account rubric, then importing the outcome into a course, then aligning the outcome to a course rubric, then viewing the outcome in the account outcomes page Change-Id: I3b1a5ead325cdcf8720351e744b3d484813e55dd Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/264212 Reviewed-by: Manoel Quirino <manoel.quirino@instructure.com> Reviewed-by: Pat Renner <prenner@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Brian Watson <bwatson@instructure.com> Product-Review: Augusto Callejas <acallejas@instructure.com>
This commit is contained in:
parent
407745792a
commit
540fd63894
|
@ -503,20 +503,17 @@ class ContentTag < ActiveRecord::Base
|
|||
scope :for_context, lambda { |context|
|
||||
case context
|
||||
when Account
|
||||
select("content_tags.*").
|
||||
joins("INNER JOIN (
|
||||
SELECT DISTINCT ct.id AS content_tag_id FROM #{ContentTag.quoted_table_name} AS ct
|
||||
INNER JOIN #{CourseAccountAssociation.quoted_table_name} AS caa ON caa.course_id = ct.context_id
|
||||
AND ct.context_type = 'Course'
|
||||
WHERE caa.account_id = #{context.id}
|
||||
UNION
|
||||
SELECT ct.id AS content_tag_id FROM #{ContentTag.quoted_table_name} AS ct
|
||||
WHERE ct.context_id = #{context.id} AND context_type = 'Account')
|
||||
AS related_content_tags ON related_content_tags.content_tag_id = content_tags.id")
|
||||
where(context: context).union(for_associated_courses(context))
|
||||
else
|
||||
where(:context_type => context.class.to_s, :context_id => context)
|
||||
where(context: context)
|
||||
end
|
||||
}
|
||||
scope :for_associated_courses, lambda { |account|
|
||||
select("DISTINCT content_tags.*").joins("INNER JOIN
|
||||
#{CourseAccountAssociation.quoted_table_name} AS caa
|
||||
ON caa.course_id = content_tags.context_id AND content_tags.context_type = 'Course'
|
||||
AND caa.account_id = #{account.id}")
|
||||
}
|
||||
scope :learning_outcome_alignments, -> { where(:tag_type => 'learning_outcome') }
|
||||
scope :learning_outcome_links, -> { where(:tag_type => 'learning_outcome_association', :associated_asset_type => 'LearningOutcomeGroup', :content_type => 'LearningOutcome') }
|
||||
|
||||
|
|
Loading…
Reference in New Issue