add release flag to load assignments by grading period

Optionally load assignments by grading period in the Gradebook.

closes EVAL-1337
flag=gradebook_load_assignments_by_grading_period

Test Plan:
1. Go to SiteAdmin settings and disable 'Load Gradebook Assignments by
   Grading Period'.
2. Go to the Gradebook in a course that uses Grading Periods. Select
   a Grading Period from the dropdown. Open the dev tools in your
   browser and then refresh the page.
3. Upon refresh, verify in the Network tab of your dev tools that there
   is a single API call to get assignment_groups, and that API call does
   not include an `assignment_ids` param. Verify that totals in the
   gradebook show correctly when switching between grading periods.
4. Go to SiteAdmin settings and enable 'Load Gradebook Assignments by
   Grading Period'.
5. Go back to the Gradebook. Select a Grading Period from the dropdown
   and then refresh the page.
6. Upon refresh, verify in the Network tab of your dev tools that there
   are two API calls to get assignment_groups, and then each contain
   `assignment_ids` params. Verify that totals in the gradebook show
   correctly when switching between grading periods.

Change-Id: I9a52613966449f811d82fe315ae5cff2984e35e4
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/254165
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Product-Review: Syed Hussain <shussain@instructure.com>
Reviewed-by: Syed Hussain <shussain@instructure.com>
Reviewed-by: Adrian Packel <apackel@instructure.com>
This commit is contained in:
Spencer Olson 2020-12-03 10:50:17 -06:00
parent b4815ed9bf
commit 7acd49014f
6 changed files with 41 additions and 9 deletions

View File

@ -434,6 +434,7 @@ class GradebooksController < ApplicationController
enrollments_with_concluded_url: custom_course_enrollments_api_url(include_concluded: true, per_page: per_page),
export_gradebook_csv_url: course_gradebook_csv_url,
final_grade_override_enabled: @context.feature_enabled?(:final_grades_override),
load_assignments_by_grading_period_enabled: Account.site_admin.feature_enabled?(:gradebook_load_assignments_by_grading_period),
gradebook_column_order_settings: @current_user.get_preference(:gradebook_column_order, @context.global_id),
gradebook_column_order_settings_url: save_gradebook_column_order_course_gradebook_url,
gradebook_column_size_settings: gradebook_column_size_preferences,

View File

@ -17,10 +17,11 @@
*/
export default class AssignmentGroupsLoader {
constructor({dispatch, gradebook, performanceControls}) {
constructor({dispatch, gradebook, performanceControls, loadAssignmentsByGradingPeriod}) {
this._dispatch = dispatch
this._gradebook = gradebook
this._performanceControls = performanceControls
this.loadAssignmentsByGradingPeriod = loadAssignmentsByGradingPeriod
}
loadAssignmentGroups() {
@ -36,6 +37,8 @@ export default class AssignmentGroupsLoader {
includes.push('module_ids')
}
// Careful when adding new params here. If the param content is too long,
// you can end up triggering a '414 Request URI Too Long' from Apache.
const params = {
exclude_assignment_submission_types: ['wiki_page'],
exclude_response_fields: [
@ -50,7 +53,7 @@ export default class AssignmentGroupsLoader {
}
const periodId = this._gradingPeriodId()
if (periodId) {
if (periodId && this.loadAssignmentsByGradingPeriod) {
return this._loadAssignmentGroupsForGradingPeriods(params, periodId)
}

View File

@ -29,7 +29,7 @@ import StudentContentDataLoader from './StudentContentDataLoader'
import StudentIdsLoader from './StudentIdsLoader'
export default class DataLoader {
constructor({gradebook, performanceControls}) {
constructor({gradebook, performanceControls, loadAssignmentsByGradingPeriod}) {
this._gradebook = gradebook
const dispatch = new RequestDispatch({
@ -39,9 +39,10 @@ export default class DataLoader {
const loaderConfig = {
dispatch,
gradebook,
performanceControls
performanceControls,
loadAssignmentsByGradingPeriod
}
this.loadAssignmentsByGradingPeriod = loadAssignmentsByGradingPeriod
this.assignmentGroupsLoader = new AssignmentGroupsLoader(loaderConfig)
this.contextModulesLoader = new ContextModulesLoader(loaderConfig)
this.customColumnsDataLoader = new CustomColumnsDataLoader(loaderConfig)
@ -123,7 +124,11 @@ export default class DataLoader {
}
if (options.getAssignmentGroups) {
if (gotGradingPeriodAssignments && gradebook.gradingPeriodId !== '0') {
if (
this.loadAssignmentsByGradingPeriod &&
gotGradingPeriodAssignments &&
gradebook.gradingPeriodId !== '0'
) {
// eslint-disable-next-line promise/catch-or-return
gotGradingPeriodAssignments.then(() => {
dataLoader.assignmentGroupsLoader.loadAssignmentGroups()

View File

@ -451,7 +451,8 @@ class Gradebook {
if (this.options.dataloader_improvements) {
this.dataLoader = new DataLoader({
gradebook: this,
performanceControls: new PerformanceControls(camelize(this.options.performance_controls))
performanceControls: new PerformanceControls(camelize(this.options.performance_controls)),
loadAssignmentsByGradingPeriod: this.options.load_assignments_by_grading_period_enabled
})
} else {
this.dataLoader = new OldDataLoader(this)

View File

@ -65,3 +65,9 @@ gradebook_csv_headers_include_grading_period:
display_name: Gradebook CSV Headers Include Grading Period
description: If set, the Gradebook CSV exporter will append the title of the selected grading
period to column headers whose values vary based on grading period.
gradebook_load_assignments_by_grading_period:
state: hidden
applies_to: SiteAdmin
display_name: Load Gradebook Assignments by Grading Period
description: If set, the Gradebook will chunk out loading of assignments, loading those for the selected
grading period first.

View File

@ -31,6 +31,7 @@ QUnit.module('Gradebook > DataLoader > AssignmentGroupsLoader', suiteHooks => {
let gradebook
let network
let performanceControls
let loadAssignmentsByGradingPeriod
suiteHooks.beforeEach(() => {
const assignments = [
@ -81,6 +82,7 @@ QUnit.module('Gradebook > DataLoader > AssignmentGroupsLoader', suiteHooks => {
network = new NetworkFake()
dispatch = new RequestDispatch()
performanceControls = new PerformanceControls()
loadAssignmentsByGradingPeriod = true
gradebook = createGradebook({
context_id: '1201'
@ -93,7 +95,13 @@ QUnit.module('Gradebook > DataLoader > AssignmentGroupsLoader', suiteHooks => {
})
function loadAssignmentGroups() {
const dataLoader = new AssignmentGroupsLoader({dispatch, gradebook, performanceControls})
const dataLoader = new AssignmentGroupsLoader({
dispatch,
gradebook,
performanceControls,
loadAssignmentsByGradingPeriod
})
return dataLoader.loadAssignmentGroups()
}
@ -150,13 +158,21 @@ QUnit.module('Gradebook > DataLoader > AssignmentGroupsLoader', suiteHooks => {
strictEqual(requests.length, 1)
})
test('makes two requests if a specific grading period is selected', async () => {
test('makes two requests if a specific grading period is selected and release flag is enabled', async () => {
loadAssignmentGroups()
await network.allRequestsReady()
const requests = getRequests()
strictEqual(requests.length, 2)
})
test('makes one request if a specific grading period is selected and release flag is disabled', async () => {
loadAssignmentsByGradingPeriod = false
loadAssignmentGroups()
await network.allRequestsReady()
const requests = getRequests()
strictEqual(requests.length, 1)
})
test('makes one request to get assignments for the current grading period', async () => {
loadAssignmentGroups()
await network.allRequestsReady()