Firestore Cloud Functions priority

后端 未结 1 546
陌清茗
陌清茗 2020-12-07 05:25

Firestore Cloud Functions priority

Now I deploy two cloud functions in the Firestore database.

They are triggered by the same document changes.

Is it

相关标签:
1条回答
  • 2020-12-07 06:22

    There is no way to indicate relative priority between functions.

    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.

    0 讨论(0)
提交回复
热议问题