Skip to content

Commit

Permalink
Merge pull request #7410 from jrjohnson/4953-clear-groups-from-tree
Browse files Browse the repository at this point in the history
Save learner group changes in two batches
  • Loading branch information
dartajax authored Sep 15, 2023
2 parents d9dd4de + 4c977c2 commit eb5742d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/components/learner-group/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export default class LearnerGroupRootComponent extends Component {
const topLevelGroup = yield learnerGroup.topLevelGroup;
const removeGroups = yield topLevelGroup.removeUserFromGroupAndAllDescendants(user);
const addGroups = yield learnerGroup.addUserToGroupAndAllParents(user);
const groups = [].concat(removeGroups).concat(addGroups);
yield all(groups.map((group) => group.save()));
yield Promise.all(removeGroups.map((g) => g.save()));
yield Promise.all(addGroups.map((g) => g.save()));
this.usersToPassToManager = yield this.createUsersToPassToManager.perform();
this.usersToPassToCohortManager = yield this.createUsersToPassToCohortManager.perform();
}
Expand All @@ -219,14 +219,20 @@ export default class LearnerGroupRootComponent extends Component {
*addUsersToGroup(users) {
const learnerGroup = this.args.learnerGroup;
const topLevelGroup = yield learnerGroup.topLevelGroup;
let groupsToSave = [];
let addGroups = [];
let removeGroups = [];
for (let i = 0; i < users.length; i++) {
const user = users[i];
const removeGroups = yield topLevelGroup.removeUserFromGroupAndAllDescendants(user);
const addGroups = yield learnerGroup.addUserToGroupAndAllParents(user);
groupsToSave = [...groupsToSave, ...removeGroups, ...addGroups];
removeGroups = [
...removeGroups,
...(yield topLevelGroup.removeUserFromGroupAndAllDescendants(user)),
];
addGroups = [...addGroups, ...(yield learnerGroup.addUserToGroupAndAllParents(user))];
}
yield all(uniqueValues(groupsToSave).map((group) => group.save()));

yield Promise.all(uniqueValues(removeGroups).map((g) => g.save()));
yield Promise.all(uniqueValues(addGroups).map((g) => g.save()));

this.usersToPassToManager = yield this.createUsersToPassToManager.perform();
this.usersToPassToCohortManager = yield this.createUsersToPassToCohortManager.perform();
}
Expand Down

0 comments on commit eb5742d

Please sign in to comment.