[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:
Keith Holliday
2017-11-07 13:19:39 -07:00
committed by GitHub
parent 0caa195c6f
commit 17ce2febf9
8 changed files with 86 additions and 19 deletions

View File

@@ -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);