Combine queries in visibility services to 2-3

The AVS makes 3 queries, and the remaining services issue just 2
queries.

flag = selective_release_optimized_services_v2
[skip-crystalball]

Test plan:
 - Specs pass
 - Regression test unassigning assignments, quizzes, pages, and
   ungraded discussions

Change-Id: I208a6a4c3e4cfc9fdad40916309395707c175222
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/356018
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Sarah Gerard <sarah.gerard@instructure.com>
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Jackson Howe <jackson.howe@instructure.com>
This commit is contained in:
Jackson Howe 2024-08-26 16:37:11 -06:00
parent 6e2ac5ac30
commit 334a04e585
9 changed files with 406 additions and 5 deletions

View File

@ -197,6 +197,24 @@ module AssignmentVisibility
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3) if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository.full_assignment_visibility_query(course_id_params:, user_id_params:, assignment_id_params:) AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository.full_assignment_visibility_query(course_id_params:, user_id_params:, assignment_id_params:)
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
visible_assignments = []
# add assignments visible to everyone
assignments_visible_to_all = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
.find_assignments_visible_to_everyone(course_id_params:, user_id_params:, assignment_id_params:)
visible_assignments |= assignments_visible_to_all
# add assignments visible to groups (only assignments can have group overrides)
assignments_visible_to_groups = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
.find_assignments_visible_to_groups(course_id_params:, user_id_params:, assignment_id_params:)
visible_assignments |= assignments_visible_to_groups
# add assignments assigned to sections, students, or the course
assignments_assigned_to_others = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
.find_assignments_assigned_to_others(course_id_params:, user_id_params:, assignment_id_params:)
visible_assignments | assignments_assigned_to_others
else else
visible_assignments = [] visible_assignments = []

View File

@ -376,6 +376,93 @@ module AssignmentVisibility
exec_find_assignment_visibility_query(query_sql:, query_params:) exec_find_assignment_visibility_query(query_sql:, query_params:)
end end
def find_assignments_assigned_to_others(course_id_params:, user_id_params:, assignment_id_params:)
filter_condition_sql = filter_condition_sql(course_id_params:, user_id_params:, assignment_id_params:)
query_sql = <<~SQL.squish
WITH #{assignment_module_items_cte_sql(course_id_params:, assignment_id_params:)}
/* assignments visible to sections */
#{assignment_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* (logical) join context modules */
#{assignment_module_items_join_sql}
/* join assignment overrides (assignment or related context module) for CourseSection */
#{VisibilitySqlHelper.assignment_override_section_join_sql(id_column_name: "assignment_id")}
/* filtered to course_id, user_id, assignment_id, and additional conditions */
#{VisibilitySqlHelper.section_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove assignments with unassigned section overrides */
#{assignment_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'CourseSection' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_section_join_sql(id_column_name: "assignment_id")}
/* filtered to course_id, user_id, assignment_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_section_filter_sql(filter_condition_sql:)}
UNION
/* assignments visible to adhoc overrides */
#{assignment_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* (logical) join context modules */
#{assignment_module_items_join_sql}
/* join assignment override for 'ADHOC' */
#{VisibilitySqlHelper.assignment_override_adhoc_join_sql(id_column_name: "assignment_id")}
/* join AssignmentOverrideStudent */
#{VisibilitySqlHelper.assignment_override_student_join_sql}
/* filtered to course_id, user_id, assignment_id, and additional conditions */
#{VisibilitySqlHelper.adhoc_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove assignments with unassigned adhoc overrides */
#{assignment_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment overrides for 'ADHOC' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_join_sql(id_column_name: "assignment_id")}
/* filtered to course_id, user_id, assignment_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_filter_sql(filter_condition_sql:)}
UNION
/* assignments visible to course overrides */
#{assignment_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'Course' */
#{VisibilitySqlHelper.assignment_override_course_join_sql(id_column_name: "assignment_id")}
/* filtered to course_id, user_id, assignment_id, and additional conditions */
#{VisibilitySqlHelper.course_override_filter_sql(filter_condition_sql:)}
SQL
query_params = query_params(course_id_params:, user_id_params:, assignment_id_params:)
exec_find_assignment_visibility_query(query_sql:, query_params:)
end
private private
def exec_find_assignment_visibility_query(query_sql:, query_params:) def exec_find_assignment_visibility_query(query_sql:, query_params:)

View File

@ -102,6 +102,19 @@ module QuizVisibility
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3) if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
QuizVisibility::Repositories::QuizVisibleToStudentRepository.full_quiz_visibility_query(course_id_params:, user_id_params:, quiz_id_params:) QuizVisibility::Repositories::QuizVisibleToStudentRepository.full_quiz_visibility_query(course_id_params:, user_id_params:, quiz_id_params:)
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
visible_quizzes = []
# add quizzes visible to everyone
quizzes_visible_to_all = QuizVisibility::Repositories::QuizVisibleToStudentRepository
.find_quizzes_visible_to_everyone(course_id_params:, user_id_params:, quiz_id_params:)
visible_quizzes |= quizzes_visible_to_all
# add quizzes assigned to sections, students, or the course
quizzes_assigned_to_others = QuizVisibility::Repositories::QuizVisibleToStudentRepository
.find_quizzes_assigned_to_others(course_id_params:, user_id_params:, quiz_id_params:)
visible_quizzes | quizzes_assigned_to_others
else else
visible_quizzes = [] visible_quizzes = []

View File

@ -333,6 +333,91 @@ module QuizVisibility
exec_find_quiz_visibility_query(query_sql:, query_params:) exec_find_quiz_visibility_query(query_sql:, query_params:)
end end
def find_quizzes_assigned_to_others(course_id_params:, user_id_params:, quiz_id_params:)
filter_condition_sql = filter_condition_sql(course_id_params:, user_id_params:, quiz_id_params:)
query_sql = <<~SQL.squish
/* quizzes visible to sections */
#{quiz_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join context modules */
#{VisibilitySqlHelper.module_items_join_sql(content_tag_type: "Quizzes::Quiz")}
/* join assignment overrides (assignment or related context module) for CourseSection */
#{VisibilitySqlHelper.assignment_override_section_join_sql(id_column_name: "quiz_id")}
/* filtered to course_id, user_id, quiz_id, and additional conditions */
#{VisibilitySqlHelper.section_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove quizzes with unassigned section overrides */
#{quiz_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'CourseSection' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_section_join_sql(id_column_name: "quiz_id")}
/* filtered to course_id, user_id, quiz_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_section_filter_sql(filter_condition_sql:)}
UNION
/* quizzes with adhoc overrides */
#{quiz_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join context modules */
#{VisibilitySqlHelper.module_items_join_sql(content_tag_type: "Quizzes::Quiz")}
/* join assignment override for 'ADHOC' */
#{VisibilitySqlHelper.assignment_override_adhoc_join_sql(id_column_name: "quiz_id")}
/* join AssignmentOverrideStudent */
#{VisibilitySqlHelper.assignment_override_student_join_sql}
/* filtered to course_id, user_id, quiz_id, and additional conditions */
#{VisibilitySqlHelper.adhoc_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove quizzes with unassigned adhoc overrides */
#{quiz_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment overrides for 'ADHOC' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_join_sql(id_column_name: "quiz_id")}
/* filtered to course_id, user_id, quiz_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_filter_sql(filter_condition_sql:)}
UNION
/* quizzes with course overrides */
#{quiz_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'Course' */
#{VisibilitySqlHelper.assignment_override_course_join_sql(id_column_name: "quiz_id")}
/* filtered to course_id, user_id, quiz_id, and additional conditions */
#{VisibilitySqlHelper.course_override_filter_sql(filter_condition_sql:)}
SQL
query_params = query_params(course_id_params:, user_id_params:, quiz_id_params:)
exec_find_quiz_visibility_query(query_sql:, query_params:)
end
private private
def exec_find_quiz_visibility_query(query_sql:, query_params:) def exec_find_quiz_visibility_query(query_sql:, query_params:)

View File

@ -334,6 +334,91 @@ module UngradedDiscussionVisibility
exec_find_discussion_topic_visibility_query(query_sql:, query_params:) exec_find_discussion_topic_visibility_query(query_sql:, query_params:)
end end
def find_discussion_topics_assigned_to_others(course_id_params:, user_id_params:, discussion_topic_id_params:)
filter_condition_sql = filter_condition_sql(course_id_params:, user_id_params:, discussion_topic_id_params:)
query_sql = <<~SQL.squish
/* discussion topics visible to sections */
#{discussion_topic_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join context modules */
#{VisibilitySqlHelper.module_items_join_sql(content_tag_type: "DiscussionTopic")}
/* join assignment overrides (assignment or related context module) for CourseSection */
#{VisibilitySqlHelper.assignment_override_section_join_sql(id_column_name: "discussion_topic_id")}
/* filtered to course_id, user_id, discussion_topic_id, and additional conditions */
#{VisibilitySqlHelper.section_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove students with unassigned section overrides */
#{discussion_topic_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'CourseSection' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_section_join_sql(id_column_name: "discussion_topic_id")}
/* filtered to course_id, user_id, discussion_topic_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_section_filter_sql(filter_condition_sql:)}
UNION
/* discussion topics with adhoc overrides */
#{discussion_topic_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join context modules */
#{VisibilitySqlHelper.module_items_join_sql(content_tag_type: "DiscussionTopic")}
/* join assignment override for 'ADHOC' */
#{VisibilitySqlHelper.assignment_override_adhoc_join_sql(id_column_name: "discussion_topic_id")}
/* join AssignmentOverrideStudent */
#{VisibilitySqlHelper.assignment_override_student_join_sql}
/* filtered to course_id, user_id, discussion_topic_id, and additional conditions */
#{VisibilitySqlHelper.adhoc_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove students with unassigned adhoc overrides */
#{discussion_topic_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment overrides for 'ADHOC' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_join_sql(id_column_name: "discussion_topic_id")}
/* filtered to course_id, user_id, discussion_topic_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_filter_sql(filter_condition_sql:)}
UNION
/* discussion topics with course overrides */
#{discussion_topic_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'Course' */
#{VisibilitySqlHelper.assignment_override_course_join_sql(id_column_name: "discussion_topic_id")}
/* filtered to course_id, user_id, discussion_topic_id, and additional conditions */
#{VisibilitySqlHelper.course_override_filter_sql(filter_condition_sql:)}
SQL
query_params = query_params(course_id_params:, user_id_params:, discussion_topic_id_params:)
exec_find_discussion_topic_visibility_query(query_sql:, query_params:)
end
private private
def exec_find_discussion_topic_visibility_query(query_sql:, query_params:) def exec_find_discussion_topic_visibility_query(query_sql:, query_params:)

View File

@ -110,6 +110,19 @@ module UngradedDiscussionVisibility
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3) if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository.full_discussion_topic_visibility_query(course_id_params:, user_id_params:, discussion_topic_id_params:) UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository.full_discussion_topic_visibility_query(course_id_params:, user_id_params:, discussion_topic_id_params:)
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
visible_discussion_topics = []
# add discussion topics visible to everyone
discussion_topics_visible_to_all = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
.find_discussion_topics_visible_to_everyone(course_id_params:, user_id_params:, discussion_topic_id_params:)
visible_discussion_topics |= discussion_topics_visible_to_all
# add discussion topics assigned to sections, students, or the course
discussion_topics_assigned_to_others = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
.find_discussion_topics_assigned_to_others(course_id_params:, user_id_params:, discussion_topic_id_params:)
visible_discussion_topics | discussion_topics_assigned_to_others
else else
visible_discussion_topics = [] visible_discussion_topics = []

View File

@ -333,6 +333,91 @@ module WikiPageVisibility
exec_find_wiki_page_visibility_query(query_sql:, query_params:) exec_find_wiki_page_visibility_query(query_sql:, query_params:)
end end
def find_wiki_pages_assigned_to_others(course_id_params:, user_id_params:, wiki_page_id_params:)
filter_condition_sql = filter_condition_sql(course_id_params:, user_id_params:, wiki_page_id_params:)
query_sql = <<~SQL.squish
/* wiki pages visible to sections */
#{wiki_page_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join context modules */
#{VisibilitySqlHelper.module_items_join_sql(content_tag_type: "WikiPage")}
/* join assignment overrides (assignment or related context module) for CourseSection */
#{VisibilitySqlHelper.assignment_override_section_join_sql(id_column_name: "wiki_page_id")}
/* filtered to course_id, user_id, wiki_page_id, and additional conditions */
#{VisibilitySqlHelper.section_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove students with unassigned section overrides */
#{wiki_page_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'CourseSection' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_section_join_sql(id_column_name: "wiki_page_id")}
/* filtered to course_id, user_id, wiki_page_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_section_filter_sql(filter_condition_sql:)}
UNION
/* wiki pages with adhoc overrides */
#{wiki_page_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join context modules */
#{VisibilitySqlHelper.module_items_join_sql(content_tag_type: "WikiPage")}
/* join assignment override for 'ADHOC' */
#{VisibilitySqlHelper.assignment_override_adhoc_join_sql(id_column_name: "wiki_page_id")}
/* join AssignmentOverrideStudent */
#{VisibilitySqlHelper.assignment_override_student_join_sql}
/* filtered to course_id, user_id, wiki_page_id, and additional conditions */
#{VisibilitySqlHelper.adhoc_override_filter_sql(filter_condition_sql:)}
EXCEPT
/* remove students with unassigned adhoc overrides */
#{wiki_page_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment overrides for 'ADHOC' (no module check) */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_join_sql(id_column_name: "wiki_page_id")}
/* filtered to course_id, user_id, wiki_page_id, and additional conditions */
#{VisibilitySqlHelper.assignment_override_unassign_adhoc_filter_sql(filter_condition_sql:)}
UNION
/* wiki pages with course overrides */
#{wiki_page_select_sql}
/* join active student enrollments */
#{VisibilitySqlHelper.enrollment_join_sql}
/* join assignment override for 'Course' */
#{VisibilitySqlHelper.assignment_override_course_join_sql(id_column_name: "wiki_page_id")}
/* filtered to course_id, user_id, wiki_page_id, and additional conditions */
#{VisibilitySqlHelper.course_override_filter_sql(filter_condition_sql:)}
SQL
query_params = query_params(course_id_params:, user_id_params:, wiki_page_id_params:)
exec_find_wiki_page_visibility_query(query_sql:, query_params:)
end
private private
def exec_find_wiki_page_visibility_query(query_sql:, query_params:) def exec_find_wiki_page_visibility_query(query_sql:, query_params:)

View File

@ -103,6 +103,19 @@ module WikiPageVisibility
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3) if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository.full_wiki_page_visibility_query(course_id_params:, user_id_params:, wiki_page_id_params:) WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository.full_wiki_page_visibility_query(course_id_params:, user_id_params:, wiki_page_id_params:)
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
visible_wiki_pages = []
# add wiki pages visible to everyone
wiki_pages_visible_to_all = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
.find_wiki_pages_visible_to_everyone(course_id_params:, user_id_params:, wiki_page_id_params:)
visible_wiki_pages |= wiki_pages_visible_to_all
# add wiki pages assigned to sections, students, or the course
wiki_pages_assigned_to_others = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
.find_wiki_pages_assigned_to_others(course_id_params:, user_id_params:, wiki_page_id_params:)
visible_wiki_pages | wiki_pages_assigned_to_others
else else
visible_wiki_pages = [] visible_wiki_pages = []

View File

@ -155,6 +155,13 @@ selective_release_optimized_services:
display_name: 'Selective Release - Optimized Visibility Services - Five Queries' display_name: 'Selective Release - Optimized Visibility Services - Five Queries'
description: |- description: |-
Optimized the visibility services used by Selective Release. Optimized the visibility services used by Selective Release.
selective_release_optimized_services_v2:
state: hidden
applies_to: SiteAdmin
display_name: 'Selective Release - Optimized Visibility Services - Three Queries'
description: |-
Optimized the visibility services used by Selective Release.
environments: environments:
ci: ci:
state: allowed_on state: allowed_on
@ -167,11 +174,6 @@ selective_release_optimized_services_v3:
display_name: 'Selective Release - Optimized Visibility Services - One Query' display_name: 'Selective Release - Optimized Visibility Services - One Query'
description: |- description: |-
Optimized the visibility services used by Selective Release. Optimized the visibility services used by Selective Release.
environments:
ci:
state: allowed_on
development:
state: allowed_on
differentiated_files: differentiated_files:
state: hidden state: hidden