云函数调用反应特别慢?
为了减轻服务器压力,我尝试用了微信的云开发,但是云函数的调用特别慢。比如下面这个函数,仅仅调用了一下云数据库而已,TTFB就超过了一秒了。很想知道是为什么?该如何解决呢? [图片] 以下是云函数调用日志: [图片] 以下是代码: exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
let type=event.type;
let name=event.name;
let price=event.price;
let mode=event.mode;
let pid=event.pid;
if(mode=="add"){
let res=await db.collection('wish').where({
openid:wxContext.OPENID,
name:name,
}).get()
if(!res.data.length){
let r=await db.collection('wish').add({
data: {
type:type,
name:name,
openid:wxContext.OPENID,
price:price,
pid:pid
},
success: function(res) {}
})
if(r._id){
return "add success";
}else{
return r;
}
}else{
return "Aready exists";
}
}else{
try {
let r=await db.collection('wish').where({
name: name,
openid:wxContext.OPENID,
}).remove();
if(r.stats.removed==1){
return "delete success";
}else if(r.stats.removed==0){
return "has been deleted";
}
} catch(e) {
console.error(e)
}
}
}