Приоритет облачных функций Firestore
Сейчас я развертываю две облачные функции в базе данных Firestore.
Они инициируются одними и теми же изменениями документа.
Можно ли указать порядок выполнения функций или последовательность триггеров? Например, я хочу, чтобы функция updateCommentNum запускала кулак, а затем запускала функцию writeUserLog. Как я мог достичь этой цели?
exports.updateCommentNum = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) =>
{
//update the comment numbers in the post/{postId}/
}
exports.writeUserLog = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) =>
{
//write the comment name,text,ID,timestamp etc. in the collection "commentlog"
}



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Невозможно указать относительный приоритет между функциями.
Если у вас есть определенный порядок, в котором вы хотите, чтобы они вызывались, используйте одну облачную функцию и просто вызовите оттуда две обычные функции:
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"
}
Это также уменьшит количество вызовов и, следовательно, снизит стоимость их эксплуатации.