Added code to update user tag list along with the existing code that already involves updating the user documents of challenge members (#12312)

* Piggybacking the updating of user tag list.

When a new task is being added to a challenge, added code to update user tag list along with the existing code that already involves syncing / updating the user documents of challenge members.

* Update comment on number of simulatenaeous users to be updated concurrently in TaskQueue.

* Added comment to explain previous commit caaca469f8 (Update comment on number of simulateneous users to be updated concurrently in TaskQueue)

* Added unit tests for testing commit caaca469f8 (Update comment on number of simulateneous users to be updated concurrently in TaskQueue)

* Removed unused lines from newly added test cases

* Implemented lint suggestions

* Update code with changes requested in PR
This commit is contained in:
tsukimi2
2020-07-04 03:55:59 +08:00
committed by GitHub
parent 453d60b5bf
commit a388abc124
2 changed files with 97 additions and 3 deletions

View File

@@ -234,8 +234,21 @@ async function _addTaskFn (challenge, tasks, memberId) {
}));
});
// Update the user
toSave.unshift(User.update({ _id: memberId }, updateTasksOrderQ).exec());
// Update the tag list of the user document of a participating member of the challenge
// such that a tag representing the challenge into which the task to be added will
// be added to the user tag list if and only if the tag does not exist already.
const addToChallengeTagSet = {
$addToSet: {
tags: {
id: challenge._id,
name: challenge.shortName,
challenge: true,
},
},
};
const updateUserParams = { ...updateTasksOrderQ, ...addToChallengeTagSet };
toSave.unshift(User.update({ _id: memberId }, updateUserParams).exec());
return Promise.all(toSave);
}
@@ -244,7 +257,7 @@ schema.methods.addTasks = async function challengeAddTasks (tasks) {
const challenge = this;
const membersIds = await _fetchMembersIds(challenge._id);
const queue = new TaskQueue(Promise, 25); // process only 5 users concurrently
const queue = new TaskQueue(Promise, 25); // process only this many users concurrently
await Promise.all(membersIds.map(queue.wrap(memberId => _addTaskFn(challenge, tasks, memberId))));
};