Firestore Cloud功能优先级 [英] Firestore Cloud Functions priority

查看:85
本文介绍了Firestore Cloud功能优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firestore云功能优先级

Firestore Cloud Functions priority

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

Now I deploy two cloud functions in the Firestore database.

它们是由同一文档更改触发。

They are triggered by the same document changes.

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

Is it possible to specify the execution order of the functions or the trigger sequence? For example, I want to let updateCommentNum function trigger fist, then trigger writeUserLog function. How could I achieve this goal?

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"

}


推荐答案

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

There is no way to indicate relative priority between functions.

如果您有一个定义的订单,您希望它们被调用,请使用单个Cloud Function并从那里调用两个常规函数:

If you have a defined order you want them invoked in, use a single Cloud Function and just call two regular functions from there:

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"
}

这也会减少调用次数,从而降低了操作成本。

That will also reduce the number of invocations, and thus reduce the cost of operating them.

这篇关于Firestore Cloud功能优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆