mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
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 commitcaaca469f8(Update comment on number of simulateneous users to be updated concurrently in TaskQueue) * Added unit tests for testing commitcaaca469f8(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:
@@ -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))));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user