javascript - Firestore Cloud Functions 优先级

标签 javascript firebase google-cloud-firestore google-cloud-functions

Firestore Cloud Functions 优先级

现在我在 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"
}

这也将减少调用次数,从而降低运行它们的成本。

关于javascript - Firestore Cloud Functions 优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52450997/

相关文章:

android - Firebase 不从控制台发送通知

firebase - 方法 'document' 没有为类型 'CollectionReference' 定义。 flutter/火力基地

Android - 如何以编程方式检查当前是否启用了 Firebase Analytics?

javascript - 如何强制 GInfoWindow 缩短它的尾部?

javascript - 是否可以获得鼠标按钮 4、5 等?

javascript - 无法调用 Javascript 类中的函数

javascript - 使用 Admin SDK 批量写入 Firestore

python - except block 未捕获 Cloud firestore 异常

java - 如何在ListView中按最大int值排列Firestore中的数据

javascript - 当我尝试将表单设置为干净时,脏表单给出错误