Refactor db read/write ops to use find instead of findOne to improve performance
This commit is contained in:
4
app.js
4
app.js
@ -310,10 +310,12 @@ app.post('/completed-bonfire/', function (req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isCompletedWith) {
|
if (isCompletedWith) {
|
||||||
User.findOne({"profile.username": isCompletedWith}, function(err, pairedWith) {
|
var paired = User.find({"profile.username": isCompletedWith}).limit(1);
|
||||||
|
paired.exec(function(err, pairedWith) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
} else {
|
} else {
|
||||||
|
pairedWith = pairedWith.pop();
|
||||||
pairedWith.bonfiresHash[bonfireHash] = {
|
pairedWith.bonfiresHash[bonfireHash] = {
|
||||||
completedWith: req.user._id,
|
completedWith: req.user._id,
|
||||||
completedDate: isCompletedDate,
|
completedDate: isCompletedDate,
|
||||||
|
@ -50,7 +50,7 @@ exports.returnBonfire = function(req, res, next) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
|
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
|
||||||
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) {
|
Bonfire.find({}, null, { sort: { difficulty: 1, bonfireNumber: 1 } }, function(err, bonfire) {
|
||||||
debug(bonfire[bonfireNumber].challengeEntryPoint);
|
debug(bonfire[bonfireNumber].challengeEntryPoint);
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
|
@ -50,7 +50,6 @@ $(document).ready(function() {
|
|||||||
},
|
},
|
||||||
url: '/completed-bonfire/'
|
url: '/completed-bonfire/'
|
||||||
});
|
});
|
||||||
console.log(didCompleteWith, bonfireSolution, thisBonfireHash); // TODO: remove debug statement
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user