gpt4 book ai didi

javascript - Parse.com 云代码 - saveAll 请求超时

转载 作者:行者123 更新时间:2023-11-29 18:25:22 25 4
gpt4 key购买 nike

我正在尝试从 Cloud Code 函数中保存对象集合。

在 30-40 个对象后,我收到超时错误。我的代码如下所示:

Parse.Cloud.define("saveInBackground", function (request, response) {
console.log("saveInBackground begin");

var objectsToSave = [];

for (var i = request.params.collectionToSave.length - 1; i >= 0; i--) {
objectsToSave.push(new LikedObject(request.params.collectionToSave[i]));
};

Parse.Object.saveAll(objectsToSave, {
success: function(list) {
// All the objects were saved.
if (response) {
response.success(list);
};

console.log("saveInBackground success");
},
error: function(model, error) {
// An error occurred while saving one of the objects.
if (response) {
response.error(error);
};

console.log("saveInBackground error: " + error.message);
}
});

console.log("saveInBackground end");
});

我可以做其他事情来保存一堆对象吗?

最佳答案

根据对象的大小,您可以尝试以 20-30 个为一组保存它们。这是必需的,因为 saveAll() 正在尝试将您提供给它的所有对象上传到服务器。以下是您可以如何操作的示例代码:

var result = true;
for (var i = request.params.collectionToSave.length - 1; i >= 0; i--) {
objectsToSave.push(new LikedObject(request.params.collectionToSave[i]));
if (i % 10 == 0) {
result = saveObjects(objectsToSave);
objectsToSave.length = 0;
}
};
if (result == true) {
console.log("saveInBackground success");
}


function saveObjects(objects) {

Parse.Object.saveAll(...);
...
}

关于javascript - Parse.com 云代码 - saveAll 请求超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14041972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com