From 4dbff4eba304b4a01b552cfb06da98b9bb6d1acc Mon Sep 17 00:00:00 2001 From: Ramin Tadayon Date: Wed, 18 Dec 2024 09:03:21 -0700 Subject: [PATCH 1/2] Flushes old Jira global storage entries on connect --- src/plus/integrations/providers/jira.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plus/integrations/providers/jira.ts b/src/plus/integrations/providers/jira.ts index ba16f793e55bf..b0835339b7f45 100644 --- a/src/plus/integrations/providers/jira.ts +++ b/src/plus/integrations/providers/jira.ts @@ -304,6 +304,8 @@ export class JiraIntegration extends IssueIntegration { if (storedOrganizations == null) { organizations = await this.getProviderResourcesForUser(this._session, true); + // Clear all other stored organizations and projects when our session changes + await this.container.storage.deleteWithPrefix('jira'); await this.container.storage.store(`jira:${this._session.accessToken}:organizations`, { v: 1, timestamp: Date.now(), From a8c404745f2d8b1ccc5a40c47dd2bb6e10101b10 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 18 Dec 2024 14:23:35 -0500 Subject: [PATCH 2/2] Changes events to provide a set of keys Avoids firing events in a loop --- src/system/vscode/storage.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/system/vscode/storage.ts b/src/system/vscode/storage.ts index 10f249c984a89..d47b4aa122905 100644 --- a/src/system/vscode/storage.ts +++ b/src/system/vscode/storage.ts @@ -18,14 +18,14 @@ export type StorageChangeEvent = /** * The key of the stored value that has changed. */ - readonly key: GlobalStorageKeys; + readonly keys: GlobalStorageKeys[]; readonly workspace: false; } | { /** * The key of the stored value that has changed. */ - readonly key: WorkspaceStorageKeys; + readonly keys: WorkspaceStorageKeys[]; readonly workspace: true; }; @@ -61,7 +61,7 @@ export class Storage implements Disposable { @debug({ logThreshold: 250 }) async delete(key: GlobalStorageKeys): Promise { await this.context.globalState.update(`${extensionPrefix}:${key}`, undefined); - this._onDidChange.fire({ key: key, workspace: false }); + this._onDidChange.fire({ keys: [key], workspace: false }); } @debug({ logThreshold: 250 }) @@ -72,6 +72,8 @@ export class Storage implements Disposable { async deleteWithPrefixCore(prefix?: ExtractPrefixes, exclude?: RegExp): Promise { const qualifiedKeyPrefix = `${extensionPrefix}:`; + const keys: GlobalStorageKeys[] = []; + for (const qualifiedKey of this.context.globalState.keys() as `${typeof extensionPrefix}:${GlobalStorageKeys}`[]) { if (!qualifiedKey.startsWith(qualifiedKeyPrefix)) continue; @@ -79,10 +81,14 @@ export class Storage implements Disposable { if (prefix == null || key === prefix || key.startsWith(`${prefix}:`)) { if (exclude?.test(key)) continue; + keys.push(key); await this.context.globalState.update(qualifiedKey, undefined); - this._onDidChange.fire({ key: key, workspace: false }); } } + + if (keys.length) { + this._onDidChange.fire({ keys: keys, workspace: false }); + } } @debug({ logThreshold: 250 }) @@ -93,7 +99,7 @@ export class Storage implements Disposable { @debug({ args: { 1: false }, logThreshold: 250 }) async store(key: T, value: GlobalStorage[T] | undefined): Promise { await this.context.globalState.update(`${extensionPrefix}:${key}`, value); - this._onDidChange.fire({ key: key, workspace: false }); + this._onDidChange.fire({ keys: [key], workspace: false }); } @debug({ args: false, logThreshold: 250 }) @@ -123,7 +129,7 @@ export class Storage implements Disposable { @debug({ logThreshold: 250 }) async deleteWorkspace(key: WorkspaceStorageKeys): Promise { await this.context.workspaceState.update(`${extensionPrefix}:${key}`, undefined); - this._onDidChange.fire({ key: key, workspace: true }); + this._onDidChange.fire({ keys: [key], workspace: true }); } @debug({ logThreshold: 250 }) @@ -137,6 +143,8 @@ export class Storage implements Disposable { ): Promise { const qualifiedKeyPrefix = `${extensionPrefix}:`; + const keys: WorkspaceStorageKeys[] = []; + for (const qualifiedKey of this.context.workspaceState.keys() as `${typeof extensionPrefix}:${WorkspaceStorageKeys}`[]) { if (!qualifiedKey.startsWith(qualifiedKeyPrefix)) continue; @@ -144,10 +152,14 @@ export class Storage implements Disposable { if (prefix == null || key === prefix || key.startsWith(`${prefix}:`)) { if (exclude?.includes(key)) continue; + keys.push(key); await this.context.workspaceState.update(qualifiedKey, undefined); - this._onDidChange.fire({ key: key, workspace: true }); } } + + if (keys.length) { + this._onDidChange.fire({ keys: keys, workspace: true }); + } } @debug({ logThreshold: 250 }) @@ -161,6 +173,6 @@ export class Storage implements Disposable { value: WorkspaceStorage[T] | undefined, ): Promise { await this.context.workspaceState.update(`${extensionPrefix}:${key}`, value); - this._onDidChange.fire({ key: key, workspace: true }); + this._onDidChange.fire({ keys: [key], workspace: true }); } }