mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
[WIP] Add initial fixes for concurrency (#9321)
* Add initial fixes for concurrency * Added memory edit for notifications * Fixed tag delete * Fixed adding and moving task order * Updated delete task * Fixed lint * Fixed task adding * Switch to mongoose push and pull
This commit is contained in:
@@ -77,6 +77,8 @@ export async function createTasks (req, res, options = {}) {
|
||||
|
||||
let toSave = Array.isArray(req.body) ? req.body : [req.body];
|
||||
|
||||
let taskOrderToAdd = {};
|
||||
|
||||
toSave = toSave.map(taskData => {
|
||||
// Validate that task.type is valid
|
||||
if (!taskData || Tasks.tasksTypes.indexOf(taskData.type) === -1) throw new BadRequest(res.t('invalidTaskType'));
|
||||
@@ -103,11 +105,23 @@ export async function createTasks (req, res, options = {}) {
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
// Otherwise update the user/challenge/group
|
||||
owner.tasksOrder[`${taskType}s`].unshift(newTask._id);
|
||||
if (!taskOrderToAdd[`${taskType}s`]) taskOrderToAdd[`${taskType}s`] = [];
|
||||
taskOrderToAdd[`${taskType}s`].unshift(newTask._id);
|
||||
|
||||
return newTask;
|
||||
});
|
||||
|
||||
// Push all task ids
|
||||
let taskOrderUpdateQuery = {$push: {}};
|
||||
for (let taskType in taskOrderToAdd) {
|
||||
taskOrderUpdateQuery.$push[`tasksOrder.${taskType}`] = {
|
||||
$each: taskOrderToAdd[taskType],
|
||||
$position: 0,
|
||||
};
|
||||
}
|
||||
|
||||
await owner.update(taskOrderUpdateQuery).exec();
|
||||
|
||||
// tasks with aliases need to be validated asyncronously
|
||||
await _validateTaskAlias(toSave, res);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user