gpt4 book ai didi

firebase - 同一触发器的多个云函数会导致问题吗? #AskFirebase

转载 作者:行者123 更新时间:2023-12-02 22:05:49 24 4
gpt4 key购买 nike

云函数是否应该针对每个触发器进行整合,或者是否可以为同一触发器编写多个函数?特别是,如果我正在阅读内部文档...是否会对性能或计费产生重大影响?

// Example: multiple onWrite functions triggered by the same Firestore doc path
functions.firestore.document('myCollection/{itemId}').onWrite((change, context) => {
// do one complex thing, potentially reading/writing data
}

functions.firestore.document('myCollection/{itemId}').onWrite((change, context) => {
// do another complex thing, potentially reading/writing the same or different data
}

或者...

// Example: one trigger and a monolithic function handling everything...
functions.firestore.document('myCollection/{itemId}').onWrite(async (change, context) => {
const otherDataSnapshot = await admin.firestore().ref('myPath').once('value').then();
this.doOneComplexThing(change, context, otherDataSnapshot);
this.doAnotherComplexThing(change, context, otherDataSnapshot);
}

const doOneComplexThing = (change, context, otherDataSnapshot) => {
// do one complex thing
}

const doAnotherComplexThing = (change, context, otherDataSnapshot) => {
// do that other complex thing
}

询问Firebase

最佳答案

如果您有两个函数触发器而不是一个,那么您将需要为每个 onWrite 的两次调用付费,而不仅仅是一次。它总是会更贵。拆分它可能有充分的理由,值得拆分,因此您必须根据您的具体情况做出决定。

关于firebase - 同一触发器的多个云函数会导致问题吗? #AskFirebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53125240/

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