代码之家  ›  专栏  ›  技术社区  ›  Methodician

同一个触发器的多个云功能会导致问题吗#AskFirebase公司

  •  1
  • Methodician  · 技术社区  · 6 年前

    云函数应该按触发器合并,还是可以为同一触发器编写多个函数?特别是,如果我在看里面的文件。。。是否存在显著的性能或计费影响?

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

    AskFirebase公司

    1 回复  |  直到 6 年前
        1
  •  3
  •   Doug Stevenson    6 年前