Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
Why is Cloud Functions for Firebase taking 25 seconds?

For clarity I have other cloud functions that all run intermittently (i.e from 'cold' in around 2-6 seconds, and all use the same boilerplate set up of importing an admin instance and exporting the function as a module)

I've seen other similar posts but this is really bugging me. I have a cloud function like so:

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 });
 });
}

I understand the 'cold start' thing but I think something is seriously wrong that it's taking 25 seconds. The logs don't return any error and are as so:

enter image description here

Is there some deeper way I can debug this to try and figure out why it's taking so long? It's unusable at the moment. Thanks a lot.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Solved: Sorry, I misunderstood the API a bit. I should have watched the promise video first!

I needed to put

return rootRef.update...

instead of

rootRef.update...
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda