3

爲了清晰起見,我還有其他的雲功能都是間歇性地運行的(例如,從大約2-6秒的「冷」開始,並且全部使用相同的樣板設置來導入管理實例並將該功能作爲模塊導出)爲什麼Firebase的雲端函數需要25秒?

我見過其他類似的帖子,但這真的讓我感到困擾。我有這樣的雲功能:

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秒。該日誌不返回任何錯誤,併爲這樣:

enter image description here

有一些更深層次的方式,我可以調試這個嘗試找出爲什麼要花這麼長時間?目前無法使用。非常感謝。

+2

薩姆嗨。我們在這裏不使用[解決]標題設備,所以我回到了早期版本。我覺得新標題是對解決方案的描述,但我們更喜歡產生解決方案的問題。即使問題是自我回答,這也有助於保持問答格式。謝謝! – halfer

+0

不用擔心謝謝澄清 –

+0

沒問題。當系統允許':-)'時,不要忘記在自己的答案上點擊刻度線。 – halfer

回答

3

已解決: 對不起, 我誤解了API了一下。我應該先看過the promise video

我需要把

return rootRef.update... 

,而不是

rootRef.update... 
相關問題