I have written a Firebase Cloud Function that triggers when a document is created. After that, I am updating documents using batch update. I have only 5 documents in the "test" collection and it is taking 7-10 seconds to update these documents. My target is maximum of 2 seconds. Is this normal or it can be optimized more?
Code:
import * as functions from "firebase-functions";
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore();
exports.onCreateOrder = functions.firestore.document('PPB/{id}/Orders/{order_id}').onCreate((snapshot, context) => {
var userRef = db.collection('test');
if (userRef != null) {
let batch = db.batch();
return userRef.get()
.then(snapshot => {
snapshot.forEach(doc => {
batch.update(doc.ref, "name", "Paul");
});
return batch.commit();
});
} else {
return null;
}
}
);