diff --git a/doc/release-notes/Next.md b/doc/release-notes/Next.md new file mode 100644 index 00000000..54bc46b6 --- /dev/null +++ b/doc/release-notes/Next.md @@ -0,0 +1 @@ +* Improve performance by caching branch objects instead of looking them up over and over \ No newline at end of file diff --git a/src/GitTfs.VsCommon/TfsHelper.Common.cs b/src/GitTfs.VsCommon/TfsHelper.Common.cs index d275e015..cfada5bc 100644 --- a/src/GitTfs.VsCommon/TfsHelper.Common.cs +++ b/src/GitTfs.VsCommon/TfsHelper.Common.cs @@ -249,14 +249,14 @@ namespace GitTfs.VsCommon public IEnumerable GetAllTfsRootBranchesOrderedByCreation() { - return VersionControl.QueryRootBranchObjects(RecursionType.Full) + return AllTfsBranchObjects .Where(b => b.Properties.ParentBranch == null) .Select(b => b.Properties.RootItem.Item); } public IEnumerable GetBranches(bool getAlsoDeletedBranches = false) { - var branches = VersionControl.QueryRootBranchObjects(RecursionType.Full); + var branches = AllTfsBranchObjects; if (getAlsoDeletedBranches) return _bridge.Wrap(branches); return _bridge.Wrap(branches.Where(b => !b.Properties.RootItem.IsDeleted)); @@ -451,6 +451,18 @@ namespace GitTfs.VsCommon } } + private BranchObject[] _allTfsBranchObjects; + private BranchObject[] AllTfsBranchObjects + { + get + { + if (_allTfsBranchObjects != null) + return _allTfsBranchObjects; + Trace.WriteLine("Looking for all branches..."); + _allTfsBranchObjects = VersionControl.QueryRootBranchObjects(RecursionType.Full); + return _allTfsBranchObjects; + } + } private IDictionary _allTfsBranches; private IDictionary AllTfsBranches { @@ -458,8 +470,7 @@ namespace GitTfs.VsCommon { if (_allTfsBranches != null) return _allTfsBranches; - Trace.WriteLine("Looking for all branches..."); - _allTfsBranches = VersionControl.QueryRootBranchObjects(RecursionType.Full) + _allTfsBranches = AllTfsBranchObjects .ToDictionary(b => b.Properties.RootItem.Item, b => b.Properties.ParentBranch != null ? b.Properties.ParentBranch.Item : null, (StringComparer.OrdinalIgnoreCase));