Javascript Firestore云功能优先级

Javascript Firestore云功能优先级,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,Firestore云功能优先级 现在,我在Firestore数据库中部署了两个云函数 它们由相同的文档更改触发 是否可以指定函数的执行顺序或触发顺序?例如,我想让updateCommentNum函数先触发,然后触发writeUserLog函数。我怎样才能达到这个目标 exports.updateCommentNum = functions.firestore .document('post/{postId}/comments/{commentsID}') .onWrite((change, co

Firestore云功能优先级

现在,我在Firestore数据库中部署了两个云函数

它们由相同的文档更改触发

是否可以指定函数的执行顺序或触发顺序?例如,我想让updateCommentNum函数先触发,然后触发writeUserLog函数。我怎样才能达到这个目标

exports.updateCommentNum = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) => 
{
    //update the comment numbers in the post/{postId}/
}


exports.writeUserLog = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) => 
{
    //write the comment name,text,ID,timestamp etc. in the collection "commentlog"

}

无法指示函数之间的相对优先级

如果您有一个要调用它们的已定义顺序,请使用单个云函数,然后从那里调用两个常规函数:

exports.onCommentWritten = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) => { 
  return Promise.all([
    updateCommentNum,
    writeUserLog
  ])
})

function updateCommentNum(change, context) {
    //update the comment numbers in the post/{postId}/
}

function writeUserLog(change, context) {
    //write the comment name,text,ID,timestamp etc. in the collection "commentlog"
}
这也将减少调用的数量,从而降低操作它们的成本