3

レコードの事前割り当てによりパフォーマンスが向上する可能性があることを読みました。これは、特に時系列データセットの多くのレコードを処理する場合に役立ちます。

updateRefLog = function(_ref,year,month,day){
    var id = _ref,"|"+year+"|"+month;
    db.collection('ref_history').count({"_id":id},function(err,count){
        // pre-allocate if needed
        if(count < 1){
            db.collection('ref_history').insert({
                "_id":id
                ,"dates":[{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0},{"count":0}]
            });
        }

        // update
        var update={"$inc":inc['dates.'+day+'.count'] = 1;};
        db.collection('ref_history').update({"_id":id},update,{upsert: true},
            function(err, res){
                if(err !== null){
                    //handle error
                }
            }
        );
    });
};

約束を守らなければならないことがこれを遅くする可能性があり、毎回カウントをチェックすると、レコードを事前に割り当てることのパフォーマンス上の利点が無効になる可能性があることを少し心配しています。

これを処理するためのよりパフォーマンスの高い方法はありますか?

4

1 に答える 1