Added fix for task order using / for arrays (#9590)

This commit is contained in:
Keith Holliday
2017-11-28 14:57:08 -06:00
committed by GitHub
parent 9ef7c45241
commit b03ddf6f7d

View File

@@ -579,19 +579,20 @@ api.scoreTask = {
// If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list // If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list
// TODO move to common code? // TODO move to common code?
let taskOrderPromise;
if (task.type === 'todo') { if (task.type === 'todo') {
if (!wasCompleted && task.completed) { if (!wasCompleted && task.completed) {
// @TODO: mongoose's push and pull should be atomic and help with // @TODO: mongoose's push and pull should be atomic and help with
// our concurrency issues. If not, we need to use this update $pull and $push // our concurrency issues. If not, we need to use this update $pull and $push
// await user.update({ taskOrderPromise = user.update({
// $pull: { 'tasksOrder.todos': task._id }, $pull: { 'tasksOrder.todos': task._id },
// }).exec(); }).exec();
user.tasksOrder.todos.pull(task._id); // user.tasksOrder.todos.pull(task._id);
} else if (wasCompleted && !task.completed && user.tasksOrder.todos.indexOf(task._id) === -1) { } else if (wasCompleted && !task.completed && user.tasksOrder.todos.indexOf(task._id) === -1) {
// await user.update({ taskOrderPromise = user.update({
// $push: { 'tasksOrder.todos': task._id }, $push: { 'tasksOrder.todos': task._id },
// }).exec(); }).exec();
user.tasksOrder.todos.push(task._id); // user.tasksOrder.todos.push(task._id);
} }
} }
@@ -609,10 +610,12 @@ api.scoreTask = {
user.markModified('_ABtests'); user.markModified('_ABtests');
} }
let results = await Bluebird.all([ let promises = [
user.save(), user.save(),
task.save(), task.save(),
]); ];
if (taskOrderPromise) promises.push(taskOrderPromise);
let results = await Bluebird.all(promises);
let savedUser = results[0]; let savedUser = results[0];