Google App Maker saving records to DB is taking 240ms per record

放肆的年华 提交于 2019-12-06 12:54:28

App Maker has ups and downs and you just need to find workarounds for the downs. I just dealt with the import of a huge database that contained over a half million records and it was quite a challenge.

In your case, I'd recommend to save items in batches to speed up the process. I think that saving records in batches of 2000 should be enough.

You can do something like this:

function saveData(){

    //get the data
    var data = getData();

    var totalRecords = data.length;
    var batchLimit = 2000;
    var totalRounds = Math.ceil(totalRecords / batchLimit);
    var round = 1;
    var roundlimit = batchLimit;
    var currentItem = 0;

    do{
        var recordsToSave = [];
        for(var i=currentItem; i<roundlimit; i++){
            var recordData = data[i];
            var newProduct = app.models.testDB.newRecord();
            newProduct.newField = recordData.newFielddData;
            newProduct.newFiled2 = recordData.newField2Data;
            recordsToSave.push(newProduct);
        }
        if(recordsToSave.length){
            app.saveRecords(recordsToSave);
        }
        currentItem += batchLimit;
        roundlimit += batchLimit;
        round++;

    } while(round <= totalRounds);

}

I used a similar solution like the one above to complete the import of 680,000+ records to appmaker. It might need a little bit more of tweaking but you get the idea. As for the latency with the connection, sorry I can't help. Hopefully a Google App Maker engineer can pitch in but as far as I see now, this is your best shot.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!