javascript - Poorly Performing Query -
i have server using store log files using mongodb. problem while browsing revision have notable delay , performace spike on server. there better way folowing:
function getrevisionslist(project,callback){ mongoclient.connect("mongodb://localhost:27017/devbed", {native_parser:true}, function(err, db) { tmp=[] if(err) { console.dir(err); } db.collection(project).find({}).toarray(function(err, items) { fillrevarr(tmp,items,0,project,callback); db.close(); }); }); } function fillrevarr(tmp,items,i,project,callback){ console.log(items) num=json.stringify(items[i].revision).replace(/["']{1}/gi,""); tmp.push("<a href=\"/"+project+"/"+num+"/log\">"+num+"</a>") if(i==items.length-1){callback(tmp)} else{fillrevarr(tmp,items,(i+1),project,callback)} }
which gives me array of revisions.
do not transform resultset array. use cursor instead:
var cursor = db.collection(project).find({}); cursor.each(function(err, item) { // ... });
Comments
Post a Comment