亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Firestore 需要一分鐘才能在 Firebase Cloud Function 中獲取文檔

Firestore 需要一分鐘才能在 Firebase Cloud Function 中獲取文檔

嚕嚕噠 2023-06-09 14:58:45
我試圖通過在 Firebase 的觸發云函數中使用 firebase-admin 來獲取內部文檔:exports.onTransactionCreated = functions.firestore  .document("transaction/{id}")  .onCreate((snapshot, context) => {    const first = Date.now();    admin.firestore().collection('myCollection').doc(snapshot.data().myDocumentId).get()    .then((documentSnapshot) => {      const second = Date.now();      functions.logger.log(`seconds total = ${Math.floor((third - first) / 1000)}`);    }}控制臺日志顯示此結果:seconds bw 1-2 elapsed = 140使用的版本:"engines": {    "node": "12"  }, "dependencies": {    "firebase-admin": "^9.2.0",    "firebase-functions": "^3.11.0"  }在什么情況下可以檢索到這么長的文檔?即使在冷啟動的情況下,我也不敢相信會這么久。這個問題實際上是我的應用程序的一大痛點,我們將不勝感激任何幫助。
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

您的函數需要返回一個在所有異步工作完成后解析的承諾?,F在,您的函數不返回任何內容,這意味著它會在不等待任何事情的情況下終止。


至少,您應該返回 返回的承諾get().then(...)。


exports.onTransactionCreated = functions.firestore

? .document("transaction/{id}")

? .onCreate((snapshot, context) => {

? ? const first = Date.now();

? ? return admin.firestore().collection('myCollection').doc(snapshot.data().myDocumentId).get()

? ? .then((documentSnapshot) => {

? ? ? const second = Date.now();

? ? ? functions.logger.log(`seconds total = ${Math.floor((third - first) / 1000)}`);

? ? }

}




查看完整回答
反對 回復 2023-06-09
  • 1 回答
  • 0 關注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號