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

163
Visualizações
Is it chaos if a Cloud Function in Node.js has at least 185 complexity?

I was trying to create a Cloud Function using Node.js. At first I created 3 files with each different function, but actually it spent almost 30-45 seconds to finish all of them just for authentication and check the device, only. Then, I decided to combine all the files into one function and now it has 185 complexity. It really became faster and it only requires 10-14 seconds.

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const level = require("../../library/level");
const hamsu = require("../../library/useful");
const db = admin.firestore();
const medium = level.medium;

exports.Authentication = functions.runWith(medium).https.onCall(async (data, context) => {
  if (context.app == undefined) {
    throw new functions.https.HttpsError(
        "failed-precondition",
        "The function must be called from an App Check verified app.");
  }
  if (!context.auth) {
    throw new functions.https.HttpsError("failed-precondition", "Unauthorized User is trying to access the App.");
  }
  let code;
  const token = data.token;
  
 });

So, what I wanna ask is does having complexity up to 185 really cause the Server into overload, or not? Thank you for any tips and tricks. Sorry, I am a newbie.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

185 is very high for cognitive complexity, and would be inadvisable in a situation where:

  • Other people need to understand and maintain your code
  • You are likely to have memory fade on how the function works
  • There is code in that function that is / needs to be duplicated elsewhere

Best practice, generally speaking, is to maintain low cognitive complexity code with as few to non instances of code repetition where possible.

An aside: I hope you enjoy the refactoring process! Some IDEs will offer a refactoring tool built into them which can automate the process somewhat.

about 4 years ago · Juan Pablo Isaza 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