如果 Node.js 中的 Cloud Function 具有至少 185 的复杂度,它会是混乱的吗?

Is it chaos if a Cloud Function in Node.js has at least 185 complexity?

我正在尝试使用 Node.js 创建云函数。起初我创建了 3 个文件,每个文件都有不同的功能,但实际上它花了将近 30-45 秒来完成所有这些文件,只是为了验证和检查设备。然后,我决定将所有文件组合成一个函数,现在它的复杂度为 185。真的变快了,只需要10-14秒

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

那么,我想问的是复杂度达到 185 是否真的会导致服务器过载? 感谢您提供任何提示和技巧。不好意思,我是新手

185 对于认知复杂度来说非常高,在以下情况下是不可取的:

  • 其他人需要理解和维护你的代码
  • 您可能对函数的工作原理记忆模糊
  • 该函数中有/需要在其他地方复制的代码

一般来说,最佳做法是尽可能少地维护低认知复杂度代码,甚至不出现代码重复。

旁白:希望您喜欢重构过程!一些 IDE 会提供一个内置的重构工具,可以在一定程度上自动化这个过程。