簡體   English   中英

firebase 的谷歌雲函數中的“獲取”函數是否每次都讀取每個文檔?

[英]Are "get" functions in Google cloud functions for firebase reading each document everytime?

我在 firebase 控制台上觀察到大量讀取,我想知道這是否來自我的“推薦功能”。

這個 function 工作得很好,但我想知道這個 function 是否會在應用擴展的情況下以瘋狂的讀取負載結束。

我的問題:這個function是不是意味着每次有用戶進來,都會占到我收藏的用戶數等量的read?

那么,由於這個 function 是一個 onUpdate,它會在每次更新文檔時重做嗎?

我不介意關於該主題的一些資源,因為我發現它在 Firebase 的網站上不清楚。

我希望我的問題很清楚!

非常感謝你!

export const onReferralInfoUpdate = functions.
firestore.document('users/{userUid}')
.onUpdate(async (change, context) => {
    const before = change.before.data();
    const after = change.after.data();
    const currentUserUid = after["uid"];

    if (before.godfather_code == after.godfather_code){
        console.log('Text did not change')
        return null
    }

    const godfatherUserSnapshot = await db.collection('users').where("referral_code", "==", after.godfather_code).get();
    const godfather = godfatherUserSnapshot.docs[0].data();
    const godfatherUid = godfather["uid"];
    
    const userRef = db.collection('users').doc(after.uid);

    const godfather_code = after.godfather_code
    
    await userRef.update({godfather_code})
    
    console.log(`the text before was >> ${before.godfather_code} << and after is ${after.godfather_code}` )

    let batch = db.batch();

    const updateGodfather = db.collection('users').doc(godfatherUid);

    batch.update(updateGodfather, {
        reward: admin.firestore.FieldValue.increment(100),
        godChildUid: admin.firestore.FieldValue.arrayUnion(currentUserUid),
    });

    return batch.commit();
    
});
    
    

是的, where("referral_code", "==", after.godfather_code).get()將在每次onUpdate() function 觸發時獲取與查詢匹配的所有文檔,您將被收取 N 次讀取費用(N = 數量匹配的文檔)。 管理員 SDK 沒有像客戶端 SDK 那樣的任何緩存。

這個function是不是意味着每進來一個用戶,就會占到我收藏的用戶數等量的read?

不是用戶集合中的文檔數量,只有與您的查詢匹配的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM