enhance: improve update filter mode performance

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-16 09:14:57 +08:00
parent 4b6bb70f20
commit 8d84d0f6a1
No known key found for this signature in database
2 changed files with 27 additions and 30 deletions

View file

@ -152,18 +152,12 @@ namespace SourceGit.Models
set; set;
} = "---"; } = "---";
public FilterMode GetHistoriesFilterMode(string pattern, FilterType type) public Dictionary<string, FilterMode> CollectHistoriesFilters()
{ {
var map = new Dictionary<string, FilterMode>();
foreach (var filter in HistoriesFilters) foreach (var filter in HistoriesFilters)
{ map.Add(filter.Pattern, filter.Mode);
if (filter.Type != type) return map;
continue;
if (filter.Pattern.Equals(pattern, StringComparison.Ordinal))
return filter.Mode;
}
return FilterMode.None;
} }
public bool UpdateHistoriesFilter(string pattern, FilterType type, FilterMode mode) public bool UpdateHistoriesFilter(string pattern, FilterType type, FilterMode mode)

View file

@ -827,9 +827,6 @@ namespace SourceGit.ViewModels
public void RefreshTags() public void RefreshTags()
{ {
var tags = new Commands.QueryTags(_fullpath).Result(); var tags = new Commands.QueryTags(_fullpath).Result();
foreach (var tag in tags)
tag.FilterMode = _settings.GetHistoriesFilterMode(tag.Name, Models.FilterType.Tag);
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
Tags = tags; Tags = tags;
@ -2035,8 +2032,9 @@ namespace SourceGit.ViewModels
builder.Run(visibles, remotes, true); builder.Run(visibles, remotes, true);
} }
UpdateBranchTreeFilterMode(builder.Locals, true); var historiesFilters = _settings.CollectHistoriesFilters();
UpdateBranchTreeFilterMode(builder.Remotes, false); UpdateBranchTreeFilterMode(builder.Locals, historiesFilters);
UpdateBranchTreeFilterMode(builder.Remotes, historiesFilters);
return builder; return builder;
} }
@ -2056,7 +2054,8 @@ namespace SourceGit.ViewModels
} }
} }
UpdateTagFilterMode(); var historiesFilters = _settings.CollectHistoriesFilters();
UpdateTagFilterMode(historiesFilters);
return visible; return visible;
} }
@ -2080,32 +2079,36 @@ namespace SourceGit.ViewModels
private void RefreshHistoriesFilters() private void RefreshHistoriesFilters()
{ {
UpdateBranchTreeFilterMode(LocalBranchTrees, true); var filters = _settings.CollectHistoriesFilters();
UpdateBranchTreeFilterMode(RemoteBranchTrees, false); UpdateBranchTreeFilterMode(LocalBranchTrees, filters);
UpdateTagFilterMode(); UpdateBranchTreeFilterMode(RemoteBranchTrees, filters);
UpdateTagFilterMode(filters);
Task.Run(RefreshCommits); Task.Run(RefreshCommits);
} }
private void UpdateBranchTreeFilterMode(List<BranchTreeNode> nodes, bool isLocal) private void UpdateBranchTreeFilterMode(List<BranchTreeNode> nodes, Dictionary<string, Models.FilterMode> filters)
{ {
foreach (var node in nodes) foreach (var node in nodes)
{ {
if (node.IsBranch) if (filters.TryGetValue(node.Path, out var value))
{ node.FilterMode = value;
node.FilterMode = _settings.GetHistoriesFilterMode(node.Path, isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch);
}
else else
{ node.FilterMode = Models.FilterMode.None;
node.FilterMode = _settings.GetHistoriesFilterMode(node.Path, isLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder);
UpdateBranchTreeFilterMode(node.Children, isLocal); if (!node.IsBranch)
} UpdateBranchTreeFilterMode(node.Children, filters);
} }
} }
private void UpdateTagFilterMode() private void UpdateTagFilterMode(Dictionary<string, Models.FilterMode> filters)
{ {
foreach (var tag in _tags) 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<BranchTreeNode> nodes) private void ResetBranchTreeFilterMode(List<BranchTreeNode> nodes)