Files
discord-decomp/_bundle/hasExceededThreshold.js
T
2026-11-01 12:12:55 +02:00

159 lines
5.1 KiB
JavaScript

// Metro module 14763 (f14764).
import _slicedToArray from "./_slicedToArray";
import { Logger } from "./log";
import { Storage } from "./Module595";
let c10410_3, c10410_4, c10410_5, c10410_6, c10410_7, c10410_8, c10410_9, c10410_10, flushViolators;
const hasExceededThreshold = function hasExceededThreshold(a0) {
return a0.name !== "anonymous" && ((c10410_7 === "" || a0.name === c10410_7) && (a0.execCount > c10410_6 || a0.execTime > c10410_5));
};
flushViolators = function flushViolators() {
if (!(function hasViolator() {
for (const item of c10410_10) {
const r24 = _slicedToArray(item, 2);
r24[0];
if (!hasExceededThreshold(r24[1])) {
continue;
}
return true;
}
return false;
})() && c10410_7 === "") {
c10410_3.log("No violators found");
} else {
(function printViolators() {
const r18 = void 0 === void 0 ? 34 : void 0;
const r17 = void 0 === void 0 ? 20 : void 0;
const r16 = void 0 === void 0 ? 20 : void 0;
const r5 = void 0 === void 0 ? r18 + r17 + r16 + 6 : void 0;
c10410_3.log("|".padEnd(r5, "-") + "|");
c10410_3.log("| Consumers of `useStateFromStores` exceeding warning thresholds:".padEnd(r5, " ") + "|");
c10410_3.log("|".padEnd(r5, "-") + "|");
c10410_3.log(`| ${"Function/Component Name".padEnd(r18, " ")}| ${"Total Exec Time".padEnd(r17, " ")}| ${"Total Exec Count".padEnd(r16, " ")}|`);
c10410_3.log("|".padEnd(r5, "-") + "|");
for (const item of c10410_10) {
const [r83, r84] = item;
if (c10410_7 !== "" && r83 === c10410_7 || hasExceededThreshold(r84)) {
const r24 = r83.padEnd(r18, " ");
c10410_3.log(`| ${r24}| ${(r84.execTime.toFixed(2) + "ms").padEnd(r17, " ")}| ${r84.execCount.toString().padEnd(r16, " ")}|`);
}
}
c10410_3.log("|".padEnd(r5, "-") + "|");
})();
}
for (const item of c10410_10) {
const [, r37] = item;
r37.warned = false;
r37.execTime = 0;
r37.execCount = 0;
}
};
c10410_3 = new Logger("useStateFromStores");
c10410_4 = 60000;
c10410_5 = 10;
c10410_6 = 1000;
c10410_7 = "";
c10410_8 = false;
c10410_9 = void 0;
c10410_10 = new Map();
export function getUseStateFromStoresExecutionWindowThresholdMs(r2 = 60000) {
return r2;
}
export function setUseStateFromStoresExecutionWindowThresholdMs(a0) {
c10410_4 = a0;
Storage.set("useStateFromStoresExecutionWindowThresholdMs", a0);
clearInterval(c10410_9);
if (c10410_8) {
c10410_9 = setInterval(flushViolators, c10410_4);
}
}
export function getUseStateFromStoresExecutionTimeWarningThresholdMs(r2 = 10) {
return r2;
}
export function setUseStateFromStoresExecutionTimeWarningThresholdMs(a0) {
c10410_5 = a0;
Storage.set("useStateFromStoresExecutionTimeWarningThresholdMs", a0);
}
export function getUseStateFromStoresExecutionCountWarningThreshold(r2 = 1000) {
return r2;
}
export function setUseStateFromStoresExecutionCountWarningThreshold(a0) {
c10410_6 = a0;
Storage.set("useStateFromStoresExecutionCountWarningThreshold", a0);
}
export function setUseStateFromStoresSpecificHookFilter(a0) {
c10410_7 = a0;
Storage.set("useStateFromStoresSpecificHookFilter", a0);
}
export function getUseStateFromStoresSpecificHookFilter(r1 = "") {
return r1;
}
export function getUseStateFromStoresDebuggingEnabled(r1 = false) {
return r1;
}
export function setUseStateFromStoresDebuggingEnabled(a0) {
c10410_8 = a0;
Storage.set("useStateFromStoresDebuggingEnabled", a0);
if (c10410_8) {
c10410_9 = setInterval(flushViolators, c10410_4);
} else {
clearInterval(c10410_9);
c10410_9 = void 0;
}
}
export function getUseStateFromStoresHookInfo() {
let r36;
if (c10410_8) {
const stack = new Error().stack;
let r12 = stack == null ? void 0 : stack.split("\n");
if (r12 == null) {
r12 = [];
}
const length = r12.length;
let r0 = 3;
const r26 = 3 < length;
let r29 = "unknown";
if (r26) {
do {
const r33 = r12[r0].trim().split(" ")[1];
const r1 = r0;
if (r33 !== "useStateFromStores" && r33 !== "useStateFromStoresArray") {
r29 = r33;
if (r29 !== "useStateFromStoresObject") {
break;
}
}
const r34 = r1 + 1;
r36 = r34 < r12.length;
r0 = r34;
r29 = "unknown";
} while (r36);
}
let r39 = c10410_10.get(r29);
const name = r29;
if (r39 == null) {
r39 = {
name,
execCount: 0,
execTime: 0,
warned: false
};
}
c10410_10.set(name, r39);
return r39;
}
}
export function trackGetStateFromStoresPerformance(a0, a1) {
if (c10410_8 && a0 != null) {
const r11 = performance.now();
const r25 = a1();
a0.execTime = a0.execTime + (performance.now() - r11);
a0.execCount = a0.execCount + 1;
if (a0.warned === false && a0.name !== "anonymous" && (c10410_7 === "" || a0.name === c10410_7) && (a0.execCount > c10410_6 || a0.execTime > c10410_5)) {
a0.warned = true;
c10410_3.log(`${a0.name} cumulatively used ${a0.execTime}ms of execution time and ran ${a0.execCount} times.`);
}
return r25;
}
return a1();
}