我使用基于NodeJS6和firestore的firebase函数,像这样的简单函数总是很慢。我还发现当我在函数中使用set/add firestore时,它总是很慢,可能只有5-10秒。这是index.js,应用程序从这个queryUserDoc接口得到响应。
`
const accountModel = require('./account');
exports.queryUserDoc = functions.https.onCall((data, context) => {
const uid = context.auth.token.uid;
return accountModel.getUserDocByUid(uid)
.then(doc => {
return JSON.stringify(({'errCode': ERROR_SUCCESS, 'data': doc.data()}));
})
.catch(err => {
return JSON.stringify(({'errCode': err}));
});
});` account.js如下:
function getUserDocByUid(uid) {
return db.collection(DB_COLLECTION_USER).doc(uid).get();
}当我的应用程序调用这个接口时,我发现了它,所以slowly.console在下面

发布于 2018-08-06 18:58:33
对我有效并显著提高了firebase函数的速度的是,更新我的函数的位置。我位于欧洲,所以默认值最初设置为us-central1。在更新到europe-west1后,速度从~5秒到~600ms。这里描述的更改区域相对容易,https://firebase.google.com/docs/functions/locations,我只是遵循了他们的例子,我已经准备好了
https://stackoverflow.com/questions/51705845
复制相似问题