From 66a9bcca446279b57466f9c5e35d8999874395fb Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 22 Sep 2024 09:11:07 +0100 Subject: [PATCH 1/3] Improve tree perf --- .vscode/settings.json | 4 +++- src/actions/ConfigureAction.ts | 2 ++ src/actions/RefreshTreeAction.ts | 9 +-------- src/commands/CommandProvider.ts | 3 +-- src/commands/RefreshTreeCommand.ts | 7 ++----- src/treeView/TreeDataProvider.ts | 25 +++++++++++++++++++++++-- src/treeView/treeCache.ts | 2 ++ 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a8c8335..1dd3734 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -59,5 +59,7 @@ "waitfor", "wdio", "Xvfb" - ] + ], + "entityframework.project": "sample_dotnet/src/Infrastructure", + "entityframework.startupProject": "sample_dotnet/ExampleAPI" } diff --git a/src/actions/ConfigureAction.ts b/src/actions/ConfigureAction.ts index 63bdf6e..57eb4aa 100644 --- a/src/actions/ConfigureAction.ts +++ b/src/actions/ConfigureAction.ts @@ -33,6 +33,7 @@ export class ConfigureAction implements IAction { value: configProject, options: { title: 'Select Project (1/2)', + ignoreFocusOut: true, }, required: true, }, @@ -42,6 +43,7 @@ export class ConfigureAction implements IAction { value: configStartupProject, options: { title: 'Select Startup Project (2/2)', + ignoreFocusOut: true, }, required: true, }, diff --git a/src/actions/RefreshTreeAction.ts b/src/actions/RefreshTreeAction.ts index cd773d3..2dbfdf1 100644 --- a/src/actions/RefreshTreeAction.ts +++ b/src/actions/RefreshTreeAction.ts @@ -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(); } } diff --git a/src/commands/CommandProvider.ts b/src/commands/CommandProvider.ts index 3026858..4e01b20 100644 --- a/src/commands/CommandProvider.ts +++ b/src/commands/CommandProvider.ts @@ -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, diff --git a/src/commands/RefreshTreeCommand.ts b/src/commands/RefreshTreeCommand.ts index e026f1c..60f392c 100644 --- a/src/commands/RefreshTreeCommand.ts +++ b/src/commands/RefreshTreeCommand.ts @@ -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(); } } diff --git a/src/treeView/TreeDataProvider.ts b/src/treeView/TreeDataProvider.ts index 3955878..9863e59 100644 --- a/src/treeView/TreeDataProvider.ts +++ b/src/treeView/TreeDataProvider.ts @@ -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(); export class TreeDataProvider extends Disposable implements vscode.TreeDataProvider { + private readonly cacheId: string; + private _onDidChangeTreeData: vscode.EventEmitter< TreeItem | undefined | null | void > = new vscode.EventEmitter(); @@ -28,6 +34,7 @@ export class TreeDataProvider private readonly cli: CLI, ) { super(); + this.cacheId = 'TreeDataProvider'; const view = vscode.window.createTreeView(`${EXTENSION_NAMESPACE}Tree`, { treeDataProvider: this, }); @@ -35,7 +42,11 @@ export class TreeDataProvider this.subscriptions.push(view); var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration( - () => this.refresh(), + e => { + if (e.affectsConfiguration(EXTENSION_NAMESPACE)) { + this.refresh(); + } + }, ); this.subscriptions.push(onDidChangeConfiguration); } @@ -55,6 +66,7 @@ export class TreeDataProvider } public refresh(): void { + clearTreeCache(); this._onDidChangeTreeData.fire(); } @@ -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; } } } diff --git a/src/treeView/treeCache.ts b/src/treeView/treeCache.ts index 5898fe4..aa88b6e 100644 --- a/src/treeView/treeCache.ts +++ b/src/treeView/treeCache.ts @@ -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(); } From 736af185fffd5026ecab00da5cd68813a5736f61 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 22 Sep 2024 09:13:28 +0100 Subject: [PATCH 2/3] Fix warnings --- sample_dotnet/ExampleAPI/WeatherForecast.cs | 2 +- .../Infrastructure/Context/BloggingContext.cs | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sample_dotnet/ExampleAPI/WeatherForecast.cs b/sample_dotnet/ExampleAPI/WeatherForecast.cs index 6c62bff..d38b1f6 100644 --- a/sample_dotnet/ExampleAPI/WeatherForecast.cs +++ b/sample_dotnet/ExampleAPI/WeatherForecast.cs @@ -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; } } diff --git a/sample_dotnet/src/Infrastructure/Context/BloggingContext.cs b/sample_dotnet/src/Infrastructure/Context/BloggingContext.cs index de4d50f..ba4de4e 100644 --- a/sample_dotnet/src/Infrastructure/Context/BloggingContext.cs +++ b/sample_dotnet/src/Infrastructure/Context/BloggingContext.cs @@ -59,9 +59,9 @@ public void Configure(EntityTypeBuilder entity) public class Blog { public int BlogId { get; set; } - public string Url { get; set; } + public required string Url { get; set; } - public List Posts { get; } = new(); + public List Posts { get; } = []; } [Table("Users")] @@ -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")] @@ -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 Tags { get; } = new List(); + public List Tags { get; } = []; - public List PostTags { get; } = new List(); + public List PostTags { get; } = []; public int? Ranking { get; set; } } @@ -101,11 +101,11 @@ public class Tag [Required] [MaxLength(64)] - public string Name { get; set; } + public required string Name { get; set; } - public List Posts { get; } = new List(); + public List Posts { get; } = []; - public List PostTags { get; } = new List(); + public List PostTags { get; } = []; } [Table("PostTags")] @@ -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; } } From 9412c1a0ddd17337d23d748b4cdd8662e724383c Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 22 Sep 2024 09:15:14 +0100 Subject: [PATCH 3/3] Improve pipeline --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 19d3b7a..9f1a849 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: os: - ubuntu-latest vscodeVersion: - - 1.64.2 + # - 1.64.2 - stable runs-on: ${{ matrix.os }} name: Build