Remove obsolete nested webpack search
This commit is contained in:
parent
63451bad25
commit
9efc0ff579
2 changed files with 3 additions and 80 deletions
|
@ -170,19 +170,10 @@ function patchFactories(factories: Record<string | number, (module: { exports: a
|
||||||
if (filter(exports)) {
|
if (filter(exports)) {
|
||||||
subscriptions.delete(filter);
|
subscriptions.delete(filter);
|
||||||
callback(exports, numberId);
|
callback(exports, numberId);
|
||||||
} else if (typeof exports === "object") {
|
} else if (exports.default && filter(exports.default)) {
|
||||||
if (exports.default && filter(exports.default)) {
|
|
||||||
subscriptions.delete(filter);
|
subscriptions.delete(filter);
|
||||||
callback(exports.default, numberId);
|
callback(exports.default, numberId);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const nested in exports) if (nested.length <= 3) {
|
|
||||||
if (exports[nested] && filter(exports[nested])) {
|
|
||||||
subscriptions.delete(filter);
|
|
||||||
callback(exports[nested], numberId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Error while firing callback for webpack chunk", err);
|
logger.error("Error while firing callback for webpack chunk", err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,44 +79,6 @@ export function _initWebpack(instance: typeof window.webpackChunkdiscord_app) {
|
||||||
if (!wreq) return false;
|
if (!wreq) return false;
|
||||||
|
|
||||||
cache = wreq.c;
|
cache = wreq.c;
|
||||||
|
|
||||||
for (const id in cache) {
|
|
||||||
const { exports } = cache[id];
|
|
||||||
if (!exports) continue;
|
|
||||||
|
|
||||||
const numberId = Number(id);
|
|
||||||
|
|
||||||
for (const callback of listeners) {
|
|
||||||
try {
|
|
||||||
callback(exports, numberId);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("Error in webpack listener", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [filter, callback] of subscriptions) {
|
|
||||||
try {
|
|
||||||
if (filter(exports)) {
|
|
||||||
subscriptions.delete(filter);
|
|
||||||
callback(exports, numberId);
|
|
||||||
} else if (typeof exports === "object") {
|
|
||||||
if (exports.default && filter(exports.default)) {
|
|
||||||
subscriptions.delete(filter);
|
|
||||||
callback(exports.default, numberId);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const nested in exports) if (nested.length <= 3) {
|
|
||||||
if (exports[nested] && filter(exports[nested])) {
|
|
||||||
subscriptions.delete(filter);
|
|
||||||
callback(exports[nested], numberId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("Error while firing callback for webpack chunk", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,20 +114,10 @@ export const find = traceFunction("find", function find(filter: FilterFn, { isIn
|
||||||
return isWaitFor ? [mod.exports, Number(key)] : mod.exports;
|
return isWaitFor ? [mod.exports, Number(key)] : mod.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof mod.exports !== "object") continue;
|
|
||||||
|
|
||||||
if (mod.exports.default && filter(mod.exports.default)) {
|
if (mod.exports.default && filter(mod.exports.default)) {
|
||||||
const found = mod.exports.default;
|
const found = mod.exports.default;
|
||||||
return isWaitFor ? [found, Number(key)] : found;
|
return isWaitFor ? [found, Number(key)] : found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the length check makes search about 20% faster
|
|
||||||
for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
|
|
||||||
const nested = mod.exports[nestedMod];
|
|
||||||
if (nested && filter(nested)) {
|
|
||||||
return isWaitFor ? [nested, Number(key)] : nested;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isIndirect) {
|
if (!isIndirect) {
|
||||||
|
@ -193,15 +145,9 @@ export function findAll(filter: FilterFn) {
|
||||||
|
|
||||||
if (filter(mod.exports))
|
if (filter(mod.exports))
|
||||||
ret.push(mod.exports);
|
ret.push(mod.exports);
|
||||||
else if (typeof mod.exports !== "object")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (mod.exports.default && filter(mod.exports.default))
|
if (mod.exports.default && filter(mod.exports.default))
|
||||||
ret.push(mod.exports.default);
|
ret.push(mod.exports.default);
|
||||||
else for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
|
|
||||||
const nested = mod.exports[nestedMod];
|
|
||||||
if (nested && filter(nested)) ret.push(nested);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -251,26 +197,12 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof mod.exports !== "object")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (mod.exports.default && filter(mod.exports.default)) {
|
if (mod.exports.default && filter(mod.exports.default)) {
|
||||||
results[j] = mod.exports.default;
|
results[j] = mod.exports.default;
|
||||||
filters[j] = undefined;
|
filters[j] = undefined;
|
||||||
if (++found === length) break outer;
|
if (++found === length) break outer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const nestedMod in mod.exports)
|
|
||||||
if (nestedMod.length <= 3) {
|
|
||||||
const nested = mod.exports[nestedMod];
|
|
||||||
if (nested && filter(nested)) {
|
|
||||||
results[j] = nested;
|
|
||||||
filters[j] = undefined;
|
|
||||||
if (++found === length) break outer;
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue