From 70b48df2881b949201552197a2a351baba7a78e4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 9 Jan 2025 13:36:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E6=9B=B4=E9=AB=98=E7=9A=84=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/ThemeChooser.razor.cs | 2 +- .../Data/WebsiteOptions.cs | 18 ++++++++++-------- .../Services/CodeSnippetService.cs | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs b/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs index b2c402f3fb4..f0ea4045a8b 100644 --- a/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs @@ -42,7 +42,7 @@ private void OnClickTheme(SelectedItem item) { _currentTheme.Clear(); WebsiteOption.CurrentValue.CurrentTheme = item.Value; - var theme = WebsiteOption.CurrentValue.Themes.Find(i => i.Key == item.Value); + var theme = WebsiteOption.CurrentValue.Themes.FirstOrDefault(i => i.Key == item.Value); if (theme is { Files: not null }) { _currentTheme.AddRange(theme.Files); diff --git a/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs b/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs index c1c36ab6512..bf3fbb00f18 100644 --- a/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs +++ b/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs @@ -3,10 +3,12 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using System.Collections.Frozen; + namespace BootstrapBlazor.Server.Data; /// -/// +/// WebsiteOptions 网站配置类 /// public class WebsiteOptions { @@ -102,12 +104,12 @@ public class WebsiteOptions /// /// 获得/设置 资源配置集合 /// - public Dictionary SourceCodes { get; private set; } + public FrozenDictionary SourceCodes { get; private set; } /// /// 获得/设置 资源配置集合 /// - public Dictionary Videos { get; private set; } + public FrozenDictionary Videos { get; private set; } /// /// 获得/设置 当前主题 @@ -127,13 +129,13 @@ public class WebsiteOptions /// /// 获得/设置 当前网站友联集合 /// - public Dictionary Links { get; set; } + public FrozenDictionary Links { get; set; } /// /// 获得/设置 网站主题配置集合 /// [NotNull] - public List? Themes { get; set; } + public HashSet? Themes { get; set; } /// /// 构造函数 @@ -141,9 +143,9 @@ public class WebsiteOptions public WebsiteOptions() { var config = GetConfiguration("docs.json"); - SourceCodes = config.GetSection("src").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value); - Videos = config.GetSection("video").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value); - Links = config.GetSection("link").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value); + SourceCodes = config.GetSection("src").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value); + Videos = config.GetSection("video").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value); + Links = config.GetSection("link").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value); #if DEBUG IsDevelopment = true; diff --git a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs index 23753976abb..645c68beffe 100644 --- a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs +++ b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs @@ -4,6 +4,7 @@ // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone using Microsoft.Extensions.Options; +using System.Collections.Frozen; namespace BootstrapBlazor.Server.Services; @@ -15,7 +16,7 @@ class CodeSnippetService private string SourceCodePath { get; set; } - private Dictionary SourceCodes { get; set; } + private FrozenDictionary SourceCodes { get; set; } private bool IsDevelopment { get; } From e772b13dcdcf4040a831dc3cbd68307be390a50a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 9 Jan 2025 13:37:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E5=86=99=E9=94=AE=E5=80=BC=E8=BD=AC=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Services/CodeSnippetService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs index 645c68beffe..e044c3bcde5 100644 --- a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs +++ b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs @@ -62,7 +62,7 @@ public async Task GetCodeAsync(string codeFile) { // codeFile = ajax.razor.cs var segs = codeFile.Split('.'); - var key = segs[0]; + var key = segs[0].ToLowerInvariant(); var typeName = SourceCodes.TryGetValue(key, out var value) ? value : string.Empty; if (!string.IsNullOrEmpty(typeName)) { From 2532713c348b646b91c88597eff4bea769d89ed4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 9 Jan 2025 13:43:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E9=94=AE?= =?UTF-8?q?=E5=80=BC=E5=8C=B9=E9=85=8D=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Services/CodeSnippetService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs index e044c3bcde5..d563d9577b6 100644 --- a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs +++ b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs @@ -62,8 +62,8 @@ public async Task GetCodeAsync(string codeFile) { // codeFile = ajax.razor.cs var segs = codeFile.Split('.'); - var key = segs[0].ToLowerInvariant(); - var typeName = SourceCodes.TryGetValue(key, out var value) ? value : string.Empty; + var key = segs[0]; + var typeName = SourceCodes.TryGetValue(key.ToLowerInvariant(), out var value) ? value : string.Empty; if (!string.IsNullOrEmpty(typeName)) { var fileName = codeFile.Replace(key, typeName);