Skip to content

Improve tree perf #114

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

Merged
merged 3 commits into from
Sep 22, 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: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
os:
- ubuntu-latest
vscodeVersion:
- 1.64.2
# - 1.64.2
- stable
runs-on: ${{ matrix.os }}
name: Build
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@
"waitfor",
"wdio",
"Xvfb"
]
],
"entityframework.project": "sample_dotnet/src/Infrastructure",
"entityframework.startupProject": "sample_dotnet/ExampleAPI"
}
2 changes: 1 addition & 1 deletion sample_dotnet/ExampleAPI/WeatherForecast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class WeatherForecast

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

public string Summary { get; set; }
public required string Summary { get; set; }
}
26 changes: 13 additions & 13 deletions sample_dotnet/src/Infrastructure/Context/BloggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public void Configure(EntityTypeBuilder<Post> entity)
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public required string Url { get; set; }

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

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

[Required]
public string Name { get; set; }
public required string Name { get; set; }
}

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

[Required]
public string Title { get; set; }
public required string Title { get; set; }

[Required]
public User User { get; set; }
public required User User { get; set; }

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

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

public int? Ranking { get; set; }
}
Expand All @@ -101,11 +101,11 @@ public class Tag

[Required]
[MaxLength(64)]
public string Name { get; set; }
public required string Name { get; set; }

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

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

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

[Required]
public Post Post { get; set; }
public required Post Post { get; set; }

[Required]
public long TagId { get; set; }
public required long TagId { get; set; }

[Required]
public Tag Tag { get; set; }
public required Tag Tag { get; set; }
}
2 changes: 2 additions & 0 deletions src/actions/ConfigureAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class ConfigureAction implements IAction {
value: configProject,
options: {
title: 'Select Project (1/2)',
ignoreFocusOut: true,
},
required: true,
},
Expand All @@ -42,6 +43,7 @@ export class ConfigureAction implements IAction {
value: configStartupProject,
options: {
title: 'Select Startup Project (2/2)',
ignoreFocusOut: true,
},
required: true,
},
Expand Down
9 changes: 1 addition & 8 deletions src/actions/RefreshTreeAction.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { clearTreeCache } from '../treeView/treeCache';
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
import type { IAction } from './IAction';

export class RefreshTreeAction implements IAction {
constructor(
private readonly treeDataProvider: TreeDataProvider,
private readonly clearCache = true,
) {}
constructor(private readonly treeDataProvider: TreeDataProvider) {}

public async run() {
if (this.clearCache) {
clearTreeCache();
}
this.treeDataProvider.refresh();
}
}
3 changes: 1 addition & 2 deletions src/commands/CommandProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export class CommandProvider extends Disposable {
);
this.registerCommand(
RefreshTreeCommand.commandName,
(clearCache: boolean) =>
new RefreshTreeCommand(treeDataProvider, clearCache),
() => new RefreshTreeCommand(treeDataProvider),
);
this.registerCommand(
RefreshDbContextTreeCommand.commandName,
Expand Down
7 changes: 2 additions & 5 deletions src/commands/RefreshTreeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import { Command } from './Command';
export class RefreshTreeCommand extends Command {
public static commandName = 'refreshTree';

constructor(
private readonly treeDataProvider: TreeDataProvider,
private readonly clearCache = true,
) {
constructor(private readonly treeDataProvider: TreeDataProvider) {
super();
}

public async run() {
await new RefreshTreeAction(this.treeDataProvider, this.clearCache).run();
await new RefreshTreeAction(this.treeDataProvider).run();
}
}
25 changes: 23 additions & 2 deletions src/treeView/TreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import { OpenMigrationFileCommand } from '../commands/OpenMigrationFileCommand';
import type { Logger } from '../util/Logger';
import { getProjectsConfig } from '../config/config';
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';
import { TreeItemCache } from './TreeItemCache';
import { clearTreeCache } from './treeCache';

export const treeDataProviderCache = new TreeItemCache<ProjectTreeItem[]>();

export class TreeDataProvider
extends Disposable
implements vscode.TreeDataProvider<vscode.TreeItem>
{
private readonly cacheId: string;

private _onDidChangeTreeData: vscode.EventEmitter<
TreeItem | undefined | null | void
> = new vscode.EventEmitter<TreeItem | undefined | null | void>();
Expand All @@ -28,14 +34,19 @@ export class TreeDataProvider
private readonly cli: CLI,
) {
super();
this.cacheId = 'TreeDataProvider';
const view = vscode.window.createTreeView(`${EXTENSION_NAMESPACE}Tree`, {
treeDataProvider: this,
});
view.onDidChangeSelection(this.handleTreeItemSelection.bind(this));
this.subscriptions.push(view);

var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(
() => this.refresh(),
e => {
if (e.affectsConfiguration(EXTENSION_NAMESPACE)) {
this.refresh();
}
},
);
this.subscriptions.push(onDidChangeConfiguration);
}
Expand All @@ -55,6 +66,7 @@ export class TreeDataProvider
}

public refresh(): void {
clearTreeCache();
this._onDidChangeTreeData.fire();
}

Expand All @@ -66,15 +78,24 @@ export class TreeDataProvider
if (element) {
return element.getChildren();
} else {
const cachedChildren = treeDataProviderCache.get(this.cacheId);

if (cachedChildren) {
return cachedChildren;
}

const { project } = getProjectsConfig();
const { projectFiles } = await ProjectFilesProvider.getProjectFiles();

return projectFiles
const projectItems = projectFiles
.filter(projectFile => !project || projectFile.name === project)
.map(
projectFile =>
new ProjectTreeItem(this.logger, projectFile, this.cli),
);

treeDataProviderCache.set(this.cacheId, projectItems);
return projectItems;
}
}
}
2 changes: 2 additions & 0 deletions src/treeView/treeCache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { dbContextsCache } from './DbContextTreeItem';
import { projectsCache } from './ProjectTreeItem';
import { treeDataProviderCache } from './TreeDataProvider';

export function clearTreeCache() {
dbContextsCache.clearAll();
projectsCache.clearAll();
treeDataProviderCache.clearAll();
}
Loading