Why cloud features for Firebase take 25 seconds?
For clarity, I have other cloud functions that all run intermittently (ie from "cold" after about 2-6 seconds and all use the same template configured to import an admin instance and export the function as a module)
I've seen other similar posts, but it really pushes me on. I have a cloud function like this:
const admin = require('../AdminConfig');
const { reportError } = require('../ReportError');
module.exports = (event) => {
const uid = event.params.uid;
const snapshot = event.data;
if (snapshot._newData === null ) {
return null;
}
console.log('Create org begin running: ', Date.now());
const organisation = event.data.val();
const rootRef = admin.database().ref();
const ref = rootRef.child('/organisations').push();
const oid = ref.key;
const userData = {
level: 'owner',
name: organisation.name,
};
const orgShiftInfo = {
name: organisation.name,
startDay: organisation.startDay || 'Monday',
};
const updatedData = {};
updatedData[`/users/${uid}/currentOrg`] = oid;
updatedData[`/users/${uid}/organisations/${oid}`] = userData;
updatedData[`/organisations/${oid}`] = organisation;
updatedData[`/org_shift_info/${oid}`] = orgShiftInfo;
rootRef.update(updatedData, (err) => {
if (err) {
return rootRef.child(`/users/${uid}/addOrgStatus`).set({ error: true })
.then(() => {
console.log(`error adding organisation for ${uid}: `, err);
return reportError(err, { uid });
});
}
console.log('Create org wrote succesfully: ', Date.now());
return rootRef.child(`/users/${uid}/addOrgStatus`).set({ success: true });
});
}
I understand cold start, but I think there is something seriously wrong that it takes 25 seconds. The logs don't return any errors and so:
Is there some deeper way to debug this to try and figure out why it's taking so long? It is currently unusable. Many thanks.
+3
source to share
1 answer
Solved: Sorry, I misunderstood the API. I had to watch the video promise first
I needed to put
return rootRef.update...
instead
rootRef.update...
+3
source to share