В журналах функций я вижу, что он работает и обновления применяются к документам, однако время ожидания истекло.
Логи показывают:
11: 41: 47.474 PM addContact Выполнение функции заняло 60003 мс, завершено
со статусом: «тайм-аут»
11: 40: 47.743 PM addContact Успешная транзакция!
11: 40: 47.659 PM addContact 9 9
11: 40: 47.659 PM addContact
11: 40: 47.659 PM addContact 8 8
11: 40: 47.656 PM addContact
11: 40: 47.472 PM addContact Выполнение функции началось
exports.addContact = functions.https.onRequest((req, res) => {
let user_id="fhr..."
let asker_id="wnz...";
let giver_id="Sp7...";
//const requestRef = admin.firestore().collection('contactRequests').doc(user_id)
const askerRef = admin.firestore().collection('users').doc(asker_id)
const giverRef = admin.firestore().collection('users').doc(giver_id)
var transaction = admin.firestore().runTransaction(t => {
return t.getAll(giverRef, askerRef)
.then(docs => {
const id1 = docs[0];
const id2 = docs[1];
if ((id1.exists && id2.exists)) {
// do stuff
let giverContacts = docs[0].data().foo
let askerContacts = docs[1].data().foo
console.log("****")
console.log(giverContacts, askerContacts)
giverContacts=giverContacts+1
askerContacts=askerContacts+1
console.log("****")
console.log(giverContacts, askerContacts)
t.update(giverRef, {foo: giverContacts})
t.update(askerRef, {foo: askerContacts})
return true
} else {
throw new Error();
}
})
})
.then(result => console.log('Transaction success!') )
.catch(err => console.log('Transaction failure:', err) );
return transaction;
* *} Тысяча двадцать-одина); * * тысяча двадцать-дв