Следует ли консолидировать облачные функции для каждого триггера, или можно написать несколько функций для одного и того же триггера? В частности, если я читаю документы внутри ... Существуют ли существенные последствия для производительности или выставления счетов?
// 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