From 8a810f37577740bcff3b0e0397eefe512577de4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Thu, 16 Apr 2015 21:01:54 +0200 Subject: [PATCH] Removed unnecessary query --- server/server.js | 71 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/server/server.js b/server/server.js index 7de67ce5..935ec0a2 100755 --- a/server/server.js +++ b/server/server.js @@ -103,10 +103,10 @@ io.on('connection', function(socket){ socket.on('end', function(id) { - db.collection(coll).find({now_playing:true}, function(err, docs){ + db.collection(coll).find({now_playing:true}, function(err, np){ //console.log(docs); //console.log(docs.length); - if(docs.length == 1 && docs[0]["id"] == id){ + if(np.length == 1 && np[0]["id"] == id){ db.collection(coll).find({views:{$exists:true}}, function(err, docs){ var startTime = docs[0]["startTime"]; if(docs[0]["removeplay"] == true) @@ -117,44 +117,43 @@ io.on('connection', function(socket){ }) }else { - db.collection(coll).find({id:id}, function(err, docs){ - if(startTime+docs[0]["duration"]<=get_time()-1) - { - db.collection(coll).update({now_playing:true, id:id}, - {$set:{ - now_playing:false, - votes:0, - guids:[] - }}, function(err, docs) + + if(startTime+np[0]["duration"]<=get_time()-1) + { + db.collection(coll).update({now_playing:true, id:id}, + {$set:{ + now_playing:false, + votes:0, + guids:[] + }}, function(err, docs) + { + //console.log(err); + //console.log(docs["n"]); + if(docs["n"] == 1) { - //console.log(err); - //console.log(docs["n"]); - if(docs["n"] == 1) - { - db.collection(coll).aggregate([ - {$match:{now_playing:false}}, - {$sort:{votes:-1, added:1}}, - {$limit:1}], function(err, docs){ - if(docs.length > 0){ - db.collection(coll).update({id:docs[0]["id"]}, - {$set:{ - now_playing:true, - votes:0, - guids:[], - added:get_time()}}, function(err, docs){ - db.collection(coll).update({views:{$exists:true}}, - {$set:{startTime:get_time(), skips:[]}}, function(err, docs){ - sort_list(coll, undefined, true, true); - }); + db.collection(coll).aggregate([ + {$match:{now_playing:false}}, + {$sort:{votes:-1, added:1}}, + {$limit:1}], function(err, docs){ + if(docs.length > 0){ + db.collection(coll).update({id:docs[0]["id"]}, + {$set:{ + now_playing:true, + votes:0, + guids:[], + added:get_time()}}, function(err, docs){ + db.collection(coll).update({views:{$exists:true}}, + {$set:{startTime:get_time(), skips:[]}}, function(err, docs){ + sort_list(coll, undefined, true, true); }); - } - }); - } + }); + } + }); + } - }); + }); - } - }); + } } }); }