Refactor db read/write ops to use find instead of findOne to improve performance

This commit is contained in:
Nathan Leniz
2015-01-24 14:21:44 -05:00
parent 0ca042a1f0
commit a7f228c410
3 changed files with 4 additions and 3 deletions

4
app.js
View File

@ -310,10 +310,12 @@ app.post('/completed-bonfire/', function (req, res) {
};
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) {
return err;
} else {
pairedWith = pairedWith.pop();
pairedWith.bonfiresHash[bonfireHash] = {
completedWith: req.user._id,
completedDate: isCompletedDate,