aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-11-28 15:44:53 +0100
committerVendicated <vendicated@riseup.net>2022-11-28 15:44:53 +0100
commit3b4879f9d9466c346385e983898efb826072ec6f (patch)
treebf78a714635236bc27f4a31b75ba72b4f3a2a550 /src/api
parenta0a1a4d139b6408419cd564611c26bd0dbade145 (diff)
downloadVencord-3b4879f9d9466c346385e983898efb826072ec6f.tar.gz
Vencord-3b4879f9d9466c346385e983898efb826072ec6f.tar.bz2
Vencord-3b4879f9d9466c346385e983898efb826072ec6f.zip
perf(settings): Cache proxies
Diffstat (limited to 'src/api')
-rw-r--r--src/api/settings.ts8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/api/settings.ts b/src/api/settings.ts
index b7499d1..9e54800 100644
--- a/src/api/settings.ts
+++ b/src/api/settings.ts
@@ -48,16 +48,18 @@ try {
var settings = JSON.parse(VencordNative.ipc.sendSync(IpcEvents.GET_SETTINGS)) as Settings;
mergeDefaults(settings, DefaultSettings);
} catch (err) {
- console.error("Corrupt settings file. ", err);
var settings = mergeDefaults({} as Settings, DefaultSettings);
+ logger.error("An error occurred while loading the settings. Corrupt settings file?\n", err);
}
type SubscriptionCallback = ((newValue: any, path: string) => void) & { _path?: string; };
const subscriptions = new Set<SubscriptionCallback>();
+const proxyCache = {} as Record<string, any>;
+
// Wraps the passed settings object in a Proxy to nicely handle change listeners and default values
function makeProxy(settings: any, root = settings, path = ""): Settings {
- return new Proxy(settings, {
+ return proxyCache[path] ??= new Proxy(settings, {
get(target, p: string) {
const v = target[p];
@@ -67,7 +69,7 @@ function makeProxy(settings: any, root = settings, path = ""): Settings {
if (path === "plugins" && p in plugins)
return target[p] = makeProxy({
enabled: plugins[p].required ?? false
- }, root, `plugins/${p}`);
+ }, root, `plugins.${p}`);
// Since the property is not set, check if this is a plugin's setting and if so, try to resolve
// the default value.