gpt4 book ai didi

javascript - Firestore Cloud Functions 优先级

转载 作者:行者123 更新时间:2023-11-30 11:19:31 26 4
gpt4 key购买 nike

Firestore Cloud Functions 优先级

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

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

是否可以指定函数的执行顺序或触发顺序?比如我想让updateCommentNum函数先触发fist,再触发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"

}

最佳答案

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

如果您有定义的调用顺序,请使用单个 Cloud Function 并从那里调用两个常规函数:

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/50340326/

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