From 8d84d0f6a15691bd52c3ccbdf7fdfeda4ca76601 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 16 Nov 2024 09:14:57 +0800 Subject: [PATCH] enhance: improve update filter mode performance Signed-off-by: leo --- src/Models/RepositorySettings.cs | 14 +++-------- src/ViewModels/Repository.cs | 43 +++++++++++++++++--------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 4027ea9f..f6796198 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -152,18 +152,12 @@ namespace SourceGit.Models set; } = "---"; - public FilterMode GetHistoriesFilterMode(string pattern, FilterType type) + public Dictionary CollectHistoriesFilters() { + var map = new Dictionary(); foreach (var filter in HistoriesFilters) - { - if (filter.Type != type) - continue; - - if (filter.Pattern.Equals(pattern, StringComparison.Ordinal)) - return filter.Mode; - } - - return FilterMode.None; + map.Add(filter.Pattern, filter.Mode); + return map; } public bool UpdateHistoriesFilter(string pattern, FilterType type, FilterMode mode) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 90847041..1847c79a 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -827,9 +827,6 @@ namespace SourceGit.ViewModels public void RefreshTags() { var tags = new Commands.QueryTags(_fullpath).Result(); - foreach (var tag in tags) - tag.FilterMode = _settings.GetHistoriesFilterMode(tag.Name, Models.FilterType.Tag); - Dispatcher.UIThread.Invoke(() => { Tags = tags; @@ -2035,8 +2032,9 @@ namespace SourceGit.ViewModels builder.Run(visibles, remotes, true); } - UpdateBranchTreeFilterMode(builder.Locals, true); - UpdateBranchTreeFilterMode(builder.Remotes, false); + var historiesFilters = _settings.CollectHistoriesFilters(); + UpdateBranchTreeFilterMode(builder.Locals, historiesFilters); + UpdateBranchTreeFilterMode(builder.Remotes, historiesFilters); return builder; } @@ -2056,7 +2054,8 @@ namespace SourceGit.ViewModels } } - UpdateTagFilterMode(); + var historiesFilters = _settings.CollectHistoriesFilters(); + UpdateTagFilterMode(historiesFilters); return visible; } @@ -2080,32 +2079,36 @@ namespace SourceGit.ViewModels private void RefreshHistoriesFilters() { - UpdateBranchTreeFilterMode(LocalBranchTrees, true); - UpdateBranchTreeFilterMode(RemoteBranchTrees, false); - UpdateTagFilterMode(); + var filters = _settings.CollectHistoriesFilters(); + UpdateBranchTreeFilterMode(LocalBranchTrees, filters); + UpdateBranchTreeFilterMode(RemoteBranchTrees, filters); + UpdateTagFilterMode(filters); Task.Run(RefreshCommits); } - private void UpdateBranchTreeFilterMode(List nodes, bool isLocal) + private void UpdateBranchTreeFilterMode(List nodes, Dictionary filters) { foreach (var node in nodes) { - if (node.IsBranch) - { - node.FilterMode = _settings.GetHistoriesFilterMode(node.Path, isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch); - } + if (filters.TryGetValue(node.Path, out var value)) + node.FilterMode = value; else - { - node.FilterMode = _settings.GetHistoriesFilterMode(node.Path, isLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder); - UpdateBranchTreeFilterMode(node.Children, isLocal); - } + node.FilterMode = Models.FilterMode.None; + + if (!node.IsBranch) + UpdateBranchTreeFilterMode(node.Children, filters); } } - private void UpdateTagFilterMode() + private void UpdateTagFilterMode(Dictionary filters) { foreach (var tag in _tags) - tag.FilterMode = _settings.GetHistoriesFilterMode(tag.Name, Models.FilterType.Tag); + { + if (filters.TryGetValue(tag.Name, out var value)) + tag.FilterMode = value; + else + tag.FilterMode = Models.FilterMode.None; + } } private void ResetBranchTreeFilterMode(List nodes)