From 312a32e7b5e7dc578b47bc0fbfd76083a50084ff Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 2 Jan 2025 04:30:18 +0100 Subject: [PATCH] =?UTF-8?q?Performance:=20only=20ping=20'allPreferences'?= =?UTF-8?q?=20when=20all=20preferences=20are=20set,=20not=20on=20every=20p?= =?UTF-8?q?reference=20added=20(which=20causes=20a=20O(n=C2=B2)=20in=20som?= =?UTF-8?q?e=20cases)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Logic/Osm/OsmPreferences.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Logic/Osm/OsmPreferences.ts b/src/Logic/Osm/OsmPreferences.ts index 4b30c4212..6c4a9d554 100644 --- a/src/Logic/Osm/OsmPreferences.ts +++ b/src/Logic/Osm/OsmPreferences.ts @@ -38,14 +38,23 @@ export class OsmPreferences { }) } - private setPreferencesAll(key: string, value: string) { + /** + * Sets a new preferenceValue in 'allPreferences' + * @param key + * @param value + * @param deferping: the end user will ping '_allPreferences' + * @private + */ + private setPreferencesAll(key: string, value: string, deferping = false) { if (this._allPreferences.data[key] !== value) { this._allPreferences.data[key] = value - this._allPreferences.ping() + if(!deferping){ + this._allPreferences.ping() + } } } - private initPreference(key: string, value: string = undefined): UIEventSource { + private initPreference(key: string, value: string = undefined, deferPing = false): UIEventSource { if (this.preferences[key] !== undefined) { if (value !== undefined) { this.preferences[key].set(value) @@ -54,12 +63,12 @@ export class OsmPreferences { } const pref = (this.preferences[key] = new UIEventSource(value, "preference: " + key)) if (value) { - this.setPreferencesAll(key, value) + this.setPreferencesAll(key, value, deferPing) } pref.addCallback((v) => { console.log("Got an update:", key, "--->", v) this.uploadKvSplit(key, v) - this.setPreferencesAll(key, v) + this.setPreferencesAll(key, v, deferPing) }) return pref } @@ -73,11 +82,12 @@ export class OsmPreferences { await this.removeLegacy(legacy) } for (const key in merged) { - this.initPreference(key, prefs[key]) + this.initPreference(key, prefs[key], true) } for (const key in legacy) { - this.initPreference(key, legacy[key]) + this.initPreference(key, legacy[key], true) } + this._allPreferences.ping() } public getPreference(key: string, defaultValue: string = undefined, prefix?: string) {