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