Skip to content

Commit

Permalink
Clear cache on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Oct 11, 2023
1 parent 43e81f3 commit 88db6e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@
},
{
"command": "terraform.cloud.workspaces.viewInBrowser",
"when": "view == terraform.cloud.workspaces",
"when": "view == terraform.cloud.workspaces && viewItem =~ /hasLink/",
"group": "inline"
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/tfc/runProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class RunTreeDataProvider implements vscode.TreeDataProvider<vscode.TreeI
if (element) {
return [element];
}
if (!this.activeWorkspace) {
if (!this.activeWorkspace || !(this.activeWorkspace instanceof WorkspaceTreeItem)) {
return [];
}

Expand Down
14 changes: 9 additions & 5 deletions src/providers/tfc/workspaceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<vscode
private readonly didChangeTreeData = new vscode.EventEmitter<void | vscode.TreeItem>();
public readonly onDidChangeTreeData = this.didChangeTreeData.event;
private projectFilter: string | undefined;
private pageSize = 10; // TODO! increase
private pageSize = 50;
private cache: vscode.TreeItem[] = [];
private totalWorkspaceCount = -1;

Expand All @@ -35,12 +35,14 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<vscode
this.ctx.subscriptions.push(
vscode.commands.registerCommand('terraform.cloud.workspaces.refresh', (workspaceItem: WorkspaceTreeItem) => {
this.reporter.sendTelemetryEvent('tfc-workspaces-refresh');
this.cache = [];
this.refresh();
this.runDataProvider.refresh(workspaceItem);
}),
vscode.commands.registerCommand('terraform.cloud.workspaces.resetProjectFilter', () => {
this.reporter.sendTelemetryEvent('tfc-workspaces-filter-reset');
this.projectFilter = undefined;
this.cache = [];
this.refresh();
}),
vscode.commands.registerCommand(
Expand All @@ -65,6 +67,7 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<vscode
this.reporter.sendTelemetryEvent('tfc-workspaces-loadMore');
this.cache = [...this.cache, ...(await this.getWorkspaces())];
this.refresh();
this.runDataProvider.refresh();
}),
);
}
Expand Down Expand Up @@ -94,6 +97,7 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<vscode
this.projectFilter = project.description;
await vscode.commands.executeCommand('setContext', 'terraform.cloud.projectFilterUsed', true);
}
this.cache = [];
this.refresh();
this.runDataProvider.refresh();
}
Expand Down Expand Up @@ -121,12 +125,12 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<vscode
}
}

const x = this.cache.slice(0);
const items = this.cache.slice(0);
if (this.totalWorkspaceCount > this.cache.length) {
x.push(new LoadMoreTreeItem());
items.push(new LoadMoreTreeItem());
}

return x;
return items;
}

private async getWorkspaces(): Promise<vscode.TreeItem[]> {
Expand Down Expand Up @@ -284,7 +288,6 @@ export class LoadMoreTreeItem extends vscode.TreeItem {
constructor() {
super('Load more...', vscode.TreeItemCollapsibleState.None);

this.description = 'Load more workspaces';
this.iconPath = new vscode.ThemeIcon('ellipsis', new vscode.ThemeColor('charts.gray'));
this.command = {
command: 'terraform.cloud.workspaces.loadMore',
Expand All @@ -311,6 +314,7 @@ export class WorkspaceTreeItem extends vscode.TreeItem {

this.description = `[${this.projectName}]`;
this.iconPath = GetRunStatusIcon(this.lastRun?.status);
this.contextValue = 'hasLink';

const lockedTxt = this.attributes.locked ? '$(lock) Locked' : '$(unlock) Unlocked';
const vscText =
Expand Down

0 comments on commit 88db6e0

Please sign in to comment.