can*_*wow 3 node.js firebase google-cloud-functions google-cloud-firestore
我使用基于 nodejs 6 和 firestore 的 firebase 函数,我这样的简单函数总是很慢。我还发现当我在函数中使用 set/add firestore 时,它总是慢可能 5-10 秒,这是 index.js,app 得到响应来自这个 queryUserDoc api。
`
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}));
});
});
Run Code Online (Sandbox Code Playgroud)
` account.js 如下:
function getUserDocByUid(uid) {
return db.collection(DB_COLLECTION_USER).doc(uid).get();
}
Run Code Online (Sandbox Code Playgroud)
对我有用并显着提高了 firebase 函数速度的是更新我函数的位置。我位于欧洲,因此默认值最初设置为us-central1. 更新europe-west1速度后,速度从~5 秒变为~600 毫秒。如此处所述更改区域相对容易 https://firebase.google.com/docs/functions/locations
我刚刚按照他们的示例进行操作,我准备好了
| 归档时间: |
|
| 查看次数: |
1772 次 |
| 最近记录: |