mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
perf: settingsstate storage performance improvements
This commit is contained in:
@@ -12,7 +12,6 @@ class StorageManager {
|
|||||||
private globalListeners: Set<GlobalChangeListener>;
|
private globalListeners: Set<GlobalChangeListener>;
|
||||||
private subscribers: Set<Subscriber<SettingsState>> = new Set();
|
private subscribers: Set<Subscriber<SettingsState>> = new Set();
|
||||||
private saveTimeout: NodeJS.Timeout | null = null;
|
private saveTimeout: NodeJS.Timeout | null = null;
|
||||||
private pendingSave = false;
|
|
||||||
private initialized = false;
|
private initialized = false;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
@@ -109,27 +108,7 @@ class StorageManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async saveToStorage(): Promise<void> {
|
public async saveToStorage(): Promise<void> {
|
||||||
// Clear any existing timeout
|
|
||||||
if (this.saveTimeout) {
|
|
||||||
clearTimeout(this.saveTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a new timeout to batch changes
|
|
||||||
this.saveTimeout = setTimeout(async () => {
|
|
||||||
if (this.pendingSave) {
|
|
||||||
// @ts-expect-error
|
|
||||||
await browser.storage.local.set(this.data);
|
|
||||||
this.notifySubscribers();
|
|
||||||
this.pendingSave = false;
|
|
||||||
}
|
|
||||||
}, 100); // Adjust delay as needed
|
|
||||||
|
|
||||||
this.pendingSave = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add immediate save method for critical updates
|
|
||||||
public async saveImmediately(): Promise<void> {
|
|
||||||
if (this.saveTimeout) {
|
if (this.saveTimeout) {
|
||||||
clearTimeout(this.saveTimeout);
|
clearTimeout(this.saveTimeout);
|
||||||
this.saveTimeout = null;
|
this.saveTimeout = null;
|
||||||
@@ -137,7 +116,6 @@ class StorageManager {
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
await browser.storage.local.set(this.data);
|
await browser.storage.local.set(this.data);
|
||||||
this.notifySubscribers();
|
this.notifySubscribers();
|
||||||
this.pendingSave = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async removeFromStorage(key: string): Promise<void> {
|
private async removeFromStorage(key: string): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user