From 6444d5796ebb2fe0a4e3a84cb25e3a094568f625 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 20 Sep 2013 15:59:17 +0200 Subject: [PATCH 1/4] set wasmodified to true if missing req.query._v --- src/controllers/auth.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/auth.js b/src/controllers/auth.js index 0d569b337c..1269dbec2d 100644 --- a/src/controllers/auth.js +++ b/src/controllers/auth.js @@ -37,7 +37,8 @@ api.auth = function(req, res, next) { if (_.isEmpty(user)) { return res.json(401, NO_USER_FOUND); } - res.locals.wasModified = +user._v !== +req.query._v; + + res.locals.wasModified = (req.query._v ? +user._v !== +req.query._v : true); res.locals.user = user; req.session.userId = user._id; return next(); From 3b273dadeeb8178f2346a76c1edf7108230b33bb Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 20 Sep 2013 16:00:07 +0200 Subject: [PATCH 2/4] typo --- src/controllers/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/auth.js b/src/controllers/auth.js index 1269dbec2d..dd4ace6c40 100644 --- a/src/controllers/auth.js +++ b/src/controllers/auth.js @@ -38,7 +38,7 @@ api.auth = function(req, res, next) { return res.json(401, NO_USER_FOUND); } - res.locals.wasModified = (req.query._v ? +user._v !== +req.query._v : true); + res.locals.wasModified = req.query._v ? +user._v !== +req.query._v : true; res.locals.user = user; req.session.userId = user._id; return next(); From 0c0e0834be421dc3c223e84a5a0d8d9b120b2d40 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 20 Sep 2013 16:01:09 +0200 Subject: [PATCH 3/4] send response only if modified or drop --- src/controllers/user.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/controllers/user.js b/src/controllers/user.js index c1373777d2..8bbbc8ace7 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -710,7 +710,14 @@ api.batchUpdate = function(req, res, next) { response = user.toJSON(); response.wasModified = res.locals.wasModified; if (response._tmp && response._tmp.drop) response.wasModified = true; - res.json(200, response); + + // Send the response to the server + if(response.wasModified){ + res.json(200, response); + }else{ + res.json(204); + } + return console.log("Reply sent"); }); }; \ No newline at end of file From 2d02e49e06ae541c3c4e94ca6e393629dca851da Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 20 Sep 2013 16:09:55 +0200 Subject: [PATCH 4/4] always send _v --- src/controllers/user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/user.js b/src/controllers/user.js index 8bbbc8ace7..2570b05445 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -715,7 +715,7 @@ api.batchUpdate = function(req, res, next) { if(response.wasModified){ res.json(200, response); }else{ - res.json(204); + res.json(200, {_v: response._v}); } return console.log("Reply sent");