Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flushes old Jira global storage entries on connect #3887

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plus/integrations/providers/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ export class JiraIntegration extends IssueIntegration<IssueIntegrationId.Jira> {

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(),
Expand Down
28 changes: 20 additions & 8 deletions src/system/vscode/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -61,7 +61,7 @@ export class Storage implements Disposable {
@debug({ logThreshold: 250 })
async delete(key: GlobalStorageKeys): Promise<void> {
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 })
Expand All @@ -72,17 +72,23 @@ export class Storage implements Disposable {
async deleteWithPrefixCore(prefix?: ExtractPrefixes<GlobalStorageKeys, ':'>, exclude?: RegExp): Promise<void> {
const qualifiedKeyPrefix = `${extensionPrefix}:`;

const keys: GlobalStorageKeys[] = [];

for (const qualifiedKey of this.context.globalState.keys() as `${typeof extensionPrefix}:${GlobalStorageKeys}`[]) {
if (!qualifiedKey.startsWith(qualifiedKeyPrefix)) continue;

const key = qualifiedKey.substring(qualifiedKeyPrefix.length) as GlobalStorageKeys;
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 })
Expand All @@ -93,7 +99,7 @@ export class Storage implements Disposable {
@debug({ args: { 1: false }, logThreshold: 250 })
async store<T extends keyof GlobalStorage>(key: T, value: GlobalStorage[T] | undefined): Promise<void> {
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 })
Expand Down Expand Up @@ -123,7 +129,7 @@ export class Storage implements Disposable {
@debug({ logThreshold: 250 })
async deleteWorkspace(key: WorkspaceStorageKeys): Promise<void> {
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 })
Expand All @@ -137,17 +143,23 @@ export class Storage implements Disposable {
): Promise<void> {
const qualifiedKeyPrefix = `${extensionPrefix}:`;

const keys: WorkspaceStorageKeys[] = [];

for (const qualifiedKey of this.context.workspaceState.keys() as `${typeof extensionPrefix}:${WorkspaceStorageKeys}`[]) {
if (!qualifiedKey.startsWith(qualifiedKeyPrefix)) continue;

const key = qualifiedKey.substring(qualifiedKeyPrefix.length) as WorkspaceStorageKeys;
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 })
Expand All @@ -161,6 +173,6 @@ export class Storage implements Disposable {
value: WorkspaceStorage[T] | undefined,
): Promise<void> {
await this.context.workspaceState.update(`${extensionPrefix}:${key}`, value);
this._onDidChange.fire({ key: key, workspace: true });
this._onDidChange.fire({ keys: [key], workspace: true });
}
}
Loading