简体   繁体   English

执行不佳的查询

[英]Poorly Performing Query

I have a server I am using to store log files using mongodb. 我有一个服务器,我用来存储使用mongodb的日志文件。 the problem is while browsing by revision I have a notable delay and a performace spike on the server. 问题是在通过修订浏览时,我有一个显着的延迟和服务器上的性能峰值。 is there a better way to do the 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 an array of all revisions. 这给了我一系列的修改。

Do not transform the resultset into an array. 不要将结果集转换为数组。 Use the cursor instead: 改为使用光标:

var cursor = db.collection(project).find({});
cursor.each(function(err, item) {
    // ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM