Skip to content

Commit 9121b92

Browse files
authored
Merge pull request #114 from badsyntax/perf
Improve tree perf
2 parents dd46482 + 9412c1a commit 9121b92

File tree

10 files changed

+49
-33
lines changed

10 files changed

+49
-33
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
os:
1515
- ubuntu-latest
1616
vscodeVersion:
17-
- 1.64.2
17+
# - 1.64.2
1818
- stable
1919
runs-on: ${{ matrix.os }}
2020
name: Build

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@
5959
"waitfor",
6060
"wdio",
6161
"Xvfb"
62-
]
62+
],
63+
"entityframework.project": "sample_dotnet/src/Infrastructure",
64+
"entityframework.startupProject": "sample_dotnet/ExampleAPI"
6365
}

sample_dotnet/ExampleAPI/WeatherForecast.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public class WeatherForecast
88

99
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
1010

11-
public string Summary { get; set; }
11+
public required string Summary { get; set; }
1212
}

sample_dotnet/src/Infrastructure/Context/BloggingContext.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public void Configure(EntityTypeBuilder<Post> entity)
5959
public class Blog
6060
{
6161
public int BlogId { get; set; }
62-
public string Url { get; set; }
62+
public required string Url { get; set; }
6363

64-
public List<Post> Posts { get; } = new();
64+
public List<Post> Posts { get; } = [];
6565
}
6666

6767
[Table("Users")]
@@ -71,7 +71,7 @@ public class User
7171
public long Id { get; set; }
7272

7373
[Required]
74-
public string Name { get; set; }
74+
public required string Name { get; set; }
7575
}
7676

7777
[Table("Posts")]
@@ -81,14 +81,14 @@ public class Post
8181
public long Id { get; set; }
8282

8383
[Required]
84-
public string Title { get; set; }
84+
public required string Title { get; set; }
8585

8686
[Required]
87-
public User User { get; set; }
87+
public required User User { get; set; }
8888

89-
public List<Tag> Tags { get; } = new List<Tag>();
89+
public List<Tag> Tags { get; } = [];
9090

91-
public List<PostTag> PostTags { get; } = new List<PostTag>();
91+
public List<PostTag> PostTags { get; } = [];
9292

9393
public int? Ranking { get; set; }
9494
}
@@ -101,11 +101,11 @@ public class Tag
101101

102102
[Required]
103103
[MaxLength(64)]
104-
public string Name { get; set; }
104+
public required string Name { get; set; }
105105

106-
public List<Post> Posts { get; } = new List<Post>();
106+
public List<Post> Posts { get; } = [];
107107

108-
public List<PostTag> PostTags { get; } = new List<PostTag>();
108+
public List<PostTag> PostTags { get; } = [];
109109
}
110110

111111
[Table("PostTags")]
@@ -115,11 +115,11 @@ public class PostTag
115115
public long PostId { get; set; }
116116

117117
[Required]
118-
public Post Post { get; set; }
118+
public required Post Post { get; set; }
119119

120120
[Required]
121-
public long TagId { get; set; }
121+
public required long TagId { get; set; }
122122

123123
[Required]
124-
public Tag Tag { get; set; }
124+
public required Tag Tag { get; set; }
125125
}

src/actions/ConfigureAction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class ConfigureAction implements IAction {
3333
value: configProject,
3434
options: {
3535
title: 'Select Project (1/2)',
36+
ignoreFocusOut: true,
3637
},
3738
required: true,
3839
},
@@ -42,6 +43,7 @@ export class ConfigureAction implements IAction {
4243
value: configStartupProject,
4344
options: {
4445
title: 'Select Startup Project (2/2)',
46+
ignoreFocusOut: true,
4547
},
4648
required: true,
4749
},

src/actions/RefreshTreeAction.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import { clearTreeCache } from '../treeView/treeCache';
21
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
32
import type { IAction } from './IAction';
43

54
export class RefreshTreeAction implements IAction {
6-
constructor(
7-
private readonly treeDataProvider: TreeDataProvider,
8-
private readonly clearCache = true,
9-
) {}
5+
constructor(private readonly treeDataProvider: TreeDataProvider) {}
106

117
public async run() {
12-
if (this.clearCache) {
13-
clearTreeCache();
14-
}
158
this.treeDataProvider.refresh();
169
}
1710
}

src/commands/CommandProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export class CommandProvider extends Disposable {
7070
);
7171
this.registerCommand(
7272
RefreshTreeCommand.commandName,
73-
(clearCache: boolean) =>
74-
new RefreshTreeCommand(treeDataProvider, clearCache),
73+
() => new RefreshTreeCommand(treeDataProvider),
7574
);
7675
this.registerCommand(
7776
RefreshDbContextTreeCommand.commandName,

src/commands/RefreshTreeCommand.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import { Command } from './Command';
55
export class RefreshTreeCommand extends Command {
66
public static commandName = 'refreshTree';
77

8-
constructor(
9-
private readonly treeDataProvider: TreeDataProvider,
10-
private readonly clearCache = true,
11-
) {
8+
constructor(private readonly treeDataProvider: TreeDataProvider) {
129
super();
1310
}
1411

1512
public async run() {
16-
await new RefreshTreeAction(this.treeDataProvider, this.clearCache).run();
13+
await new RefreshTreeAction(this.treeDataProvider).run();
1714
}
1815
}

src/treeView/TreeDataProvider.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import { OpenMigrationFileCommand } from '../commands/OpenMigrationFileCommand';
1010
import type { Logger } from '../util/Logger';
1111
import { getProjectsConfig } from '../config/config';
1212
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';
13+
import { TreeItemCache } from './TreeItemCache';
14+
import { clearTreeCache } from './treeCache';
15+
16+
export const treeDataProviderCache = new TreeItemCache<ProjectTreeItem[]>();
1317

1418
export class TreeDataProvider
1519
extends Disposable
1620
implements vscode.TreeDataProvider<vscode.TreeItem>
1721
{
22+
private readonly cacheId: string;
23+
1824
private _onDidChangeTreeData: vscode.EventEmitter<
1925
TreeItem | undefined | null | void
2026
> = new vscode.EventEmitter<TreeItem | undefined | null | void>();
@@ -28,14 +34,19 @@ export class TreeDataProvider
2834
private readonly cli: CLI,
2935
) {
3036
super();
37+
this.cacheId = 'TreeDataProvider';
3138
const view = vscode.window.createTreeView(`${EXTENSION_NAMESPACE}Tree`, {
3239
treeDataProvider: this,
3340
});
3441
view.onDidChangeSelection(this.handleTreeItemSelection.bind(this));
3542
this.subscriptions.push(view);
3643

3744
var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(
38-
() => this.refresh(),
45+
e => {
46+
if (e.affectsConfiguration(EXTENSION_NAMESPACE)) {
47+
this.refresh();
48+
}
49+
},
3950
);
4051
this.subscriptions.push(onDidChangeConfiguration);
4152
}
@@ -55,6 +66,7 @@ export class TreeDataProvider
5566
}
5667

5768
public refresh(): void {
69+
clearTreeCache();
5870
this._onDidChangeTreeData.fire();
5971
}
6072

@@ -66,15 +78,24 @@ export class TreeDataProvider
6678
if (element) {
6779
return element.getChildren();
6880
} else {
81+
const cachedChildren = treeDataProviderCache.get(this.cacheId);
82+
83+
if (cachedChildren) {
84+
return cachedChildren;
85+
}
86+
6987
const { project } = getProjectsConfig();
7088
const { projectFiles } = await ProjectFilesProvider.getProjectFiles();
7189

72-
return projectFiles
90+
const projectItems = projectFiles
7391
.filter(projectFile => !project || projectFile.name === project)
7492
.map(
7593
projectFile =>
7694
new ProjectTreeItem(this.logger, projectFile, this.cli),
7795
);
96+
97+
treeDataProviderCache.set(this.cacheId, projectItems);
98+
return projectItems;
7899
}
79100
}
80101
}

src/treeView/treeCache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { dbContextsCache } from './DbContextTreeItem';
22
import { projectsCache } from './ProjectTreeItem';
3+
import { treeDataProviderCache } from './TreeDataProvider';
34

45
export function clearTreeCache() {
56
dbContextsCache.clearAll();
67
projectsCache.clearAll();
8+
treeDataProviderCache.clearAll();
79
}

0 commit comments

Comments
 (0)