为清楚起见,我还有其他所有间歇性运行的云函数(即从“冷”运行大约 2-6 秒,并且都使用相同的样板设置导入管理实例并将函数导出为模块)
我看过其他类似的帖子,但这真的让我很烦。我有一个像这样的云功能:
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 });
});
}
我理解“冷启动”这件事,但我认为需要 25 秒的时间是严重错误的。日志不返回任何错误,如下所示:
是否有一些更深入的方法可以调试它以尝试弄清楚为什么要花这么长时间?目前无法使用。非常感谢。
最佳答案
关于node.js - 为什么 Cloud Functions for Firebase 需要 25 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43637519/