mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 19:55:00 +00:00
perf: set/update TimeToSort
while creating branch nodes
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
c8e21673e4
commit
bbc840a5cb
1 changed files with 6 additions and 34 deletions
|
@ -120,28 +120,19 @@ namespace SourceGit.ViewModels
|
||||||
folders.Clear();
|
folders.Clear();
|
||||||
|
|
||||||
if (_localSortMode == Models.BranchSortMode.Name)
|
if (_localSortMode == Models.BranchSortMode.Name)
|
||||||
{
|
|
||||||
SortNodesByName(_locals);
|
SortNodesByName(_locals);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
SetTimeToSortRecusive(_locals);
|
|
||||||
SortNodesByTime(_locals);
|
SortNodesByTime(_locals);
|
||||||
}
|
|
||||||
|
|
||||||
if (_remoteSortMode == Models.BranchSortMode.Name)
|
if (_remoteSortMode == Models.BranchSortMode.Name)
|
||||||
{
|
|
||||||
SortNodesByName(_remotes);
|
SortNodesByName(_remotes);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
SetTimeToSortRecusive(_remotes);
|
|
||||||
SortNodesByTime(_remotes);
|
SortNodesByTime(_remotes);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Dictionary<string, BranchTreeNode> folders, string prefix, bool bForceExpanded)
|
private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Dictionary<string, BranchTreeNode> folders, string prefix, bool bForceExpanded)
|
||||||
{
|
{
|
||||||
|
var time = branch.CommitterDate;
|
||||||
var fullpath = $"{prefix}/{branch.Name}";
|
var fullpath = $"{prefix}/{branch.Name}";
|
||||||
var sepIdx = branch.Name.IndexOf('/', StringComparison.Ordinal);
|
var sepIdx = branch.Name.IndexOf('/', StringComparison.Ordinal);
|
||||||
if (sepIdx == -1 || branch.IsDetachedHead)
|
if (sepIdx == -1 || branch.IsDetachedHead)
|
||||||
|
@ -152,7 +143,7 @@ namespace SourceGit.ViewModels
|
||||||
Path = fullpath,
|
Path = fullpath,
|
||||||
Backend = branch,
|
Backend = branch,
|
||||||
IsExpanded = false,
|
IsExpanded = false,
|
||||||
TimeToSort = branch.CommitterDate,
|
TimeToSort = time,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -167,6 +158,7 @@ namespace SourceGit.ViewModels
|
||||||
if (folders.TryGetValue(folder, out var val))
|
if (folders.TryGetValue(folder, out var val))
|
||||||
{
|
{
|
||||||
lastFolder = val;
|
lastFolder = val;
|
||||||
|
lastFolder.TimeToSort = Math.Max(lastFolder.TimeToSort, time);
|
||||||
if (!lastFolder.IsExpanded)
|
if (!lastFolder.IsExpanded)
|
||||||
lastFolder.IsExpanded |= (branch.IsCurrent || _expanded.Contains(folder));
|
lastFolder.IsExpanded |= (branch.IsCurrent || _expanded.Contains(folder));
|
||||||
}
|
}
|
||||||
|
@ -177,6 +169,7 @@ namespace SourceGit.ViewModels
|
||||||
Name = name,
|
Name = name,
|
||||||
Path = folder,
|
Path = folder,
|
||||||
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
|
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
|
||||||
|
TimeToSort = time,
|
||||||
};
|
};
|
||||||
roots.Add(lastFolder);
|
roots.Add(lastFolder);
|
||||||
folders.Add(folder, lastFolder);
|
folders.Add(folder, lastFolder);
|
||||||
|
@ -188,6 +181,7 @@ namespace SourceGit.ViewModels
|
||||||
Name = name,
|
Name = name,
|
||||||
Path = folder,
|
Path = folder,
|
||||||
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
|
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
|
||||||
|
TimeToSort = time,
|
||||||
};
|
};
|
||||||
lastFolder.Children.Add(cur);
|
lastFolder.Children.Add(cur);
|
||||||
folders.Add(folder, cur);
|
folders.Add(folder, cur);
|
||||||
|
@ -204,7 +198,7 @@ namespace SourceGit.ViewModels
|
||||||
Path = fullpath,
|
Path = fullpath,
|
||||||
Backend = branch,
|
Backend = branch,
|
||||||
IsExpanded = false,
|
IsExpanded = false,
|
||||||
TimeToSort = branch.CommitterDate,
|
TimeToSort = time,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,28 +247,6 @@ namespace SourceGit.ViewModels
|
||||||
SortNodesByTime(node.Children);
|
SortNodesByTime(node.Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ulong SetTimeToSortRecusive(List<BranchTreeNode> nodes)
|
|
||||||
{
|
|
||||||
var recent = (ulong)0;
|
|
||||||
|
|
||||||
foreach (var node in nodes)
|
|
||||||
{
|
|
||||||
if (node.Backend is Models.Branch)
|
|
||||||
{
|
|
||||||
recent = Math.Max(recent, node.TimeToSort);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var time = SetTimeToSortRecusive(node.Children);
|
|
||||||
recent = Math.Max(recent, time);
|
|
||||||
|
|
||||||
if (node.Backend is not Models.Remote)
|
|
||||||
node.TimeToSort = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
return recent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Models.BranchSortMode _localSortMode = Models.BranchSortMode.Name;
|
private readonly Models.BranchSortMode _localSortMode = Models.BranchSortMode.Name;
|
||||||
private readonly Models.BranchSortMode _remoteSortMode = Models.BranchSortMode.Name;
|
private readonly Models.BranchSortMode _remoteSortMode = Models.BranchSortMode.Name;
|
||||||
private readonly List<BranchTreeNode> _locals = new List<BranchTreeNode>();
|
private readonly List<BranchTreeNode> _locals = new List<BranchTreeNode>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue