我正在为Visual Studio 2013 / Team Foundation Server 2012编写扩展程序。
我有一个带有treeview和listview的用户控件。树视图显示所选团队项目中的分支以及所有子文件夹。列表视图列出了所选文件夹中包含的文件以及每个文件的一些基本信息,如最后一个登记日期,最后一个进行更改的用户等。
我首先拉动所选文件夹中的项目,然后获取每个项目的最新变化集:
Public Sub GetSourceControlDetailDefault(ByVal strFolder As String, Optional recursionType__1 As RecursionType = RecursionType.OneLevel)
SourceControlListViewItems.Clear()
Dim serverItem As String = strFolder + "/"
Dim itemSet As ItemSet = Nothing
Dim spec As New ItemSpec(serverItem, recursionType__1)
itemSet = TfsShared.Instance.Vcs.GetItems(spec, VersionSpec.Latest, DeletedState.NonDeleted, ItemType.File, False)
For Each item In itemSet.Items
Dim chgDetail As Changeset = GetDetails(item.ChangesetId.ToString(), item.ServerItem.ToString())
SourceControlListViewItems.Add(New ItemClass(item, chgDetail))
Next
End Sub
Public Function GetDetails(ByVal cID As String, iName As String) As Changeset
Dim serverItem As String = iName
Dim latest As Changeset
Dim version As New ChangesetVersionSpec(cID)
latest = TfsShared.Instance.Vcs.QueryHistory(serverItem, VersionSpec.Latest, 0, RecursionType.None, Nothing, version, _
version, 1, False, False, False).Cast(Of Changeset)().First()
Return latest
End Function
Public Property SourceControlListViewItems() As ObservableCollection(Of ItemClass)
Get
Return m_SourceControlListViewItems
End Get
Set(value As ObservableCollection(Of ItemClass))
m_SourceControlListViewItems = value
End Set
End Property
Private m_SourceControlListViewItems As ObservableCollection(Of ItemClass)
我的ItemClass实现了INotifyPropertyChanged,并为我提取的详细信息设置了get / set。
这一切都有效 - 我得到了我想要正确显示的信息。问题是它非常慢。包含20个项目的文件夹需要8秒钟才能加载。包含129个项目的文件夹需要40秒才能加载。我们的文件夹远远超过129件。
如果我只加载项目,那就非常快。只有当我为每个项目拉动变速集时,它才会减速。不幸的是,我想要显示的大部分信息都不包含在项目中。
我能做些什么来提高效率吗?在这个速度下它是无法使用的。
谢谢!
答案 0 :(得分:1)
感谢Ahmed ilyas让我以不同的方式思考这个问题。
在拉动itemSet之后,我现在在一个查询中获取所选文件夹的所有更改集并将它们存储在本地变量中。然后我可以在本地拉出适当的变更集。即使是包含600多个文件的文件夹现在也只需要3秒钟即可加载。
Public Sub GetSourceControlDetailDefault(ByVal strFolder As String, Optional recursionType__1 As RecursionType = RecursionType.OneLevel)
SourceControlListViewItems.Clear()
Dim serverItem As String = strFolder + "/"
Dim itemSet As ItemSet = Nothing
Dim spec As New ItemSpec(serverItem, recursionType__1)
itemSet = TfsShared.Instance.Vcs.GetItems(spec, VersionSpec.Latest, DeletedState.NonDeleted, ItemType.File, False)
GetFolderChangesets(strFolder)
For Each item In itemSet.Items
Dim chgDetail As Changeset = GetChangesetDetails(item.ChangesetId.ToString())
SourceControlListViewItems.Add(New ItemClass(item, chgDetail ))
End If
Next
End Sub
Public Sub GetFolderChangesets(ByVal strFolder As String)
Dim serverItem As String = strFolder + "/*"
Dim spec As New ItemSpec(serverItem, RecursionType.Full)
Dim versionFrom As New ChangesetVersionSpec(1)
m_folderChangesets = TfsShared.Instance.Vcs.QueryHistory(serverItem, VersionSpec.Latest, 0, RecursionType.Full, Nothing, versionFrom, _
VersionSpec.Latest, Integer.MaxValue, False, False, False).Cast(Of Changeset)().ToList()
End Sub
Public Property FolderChangesets() As List(Of Changeset)
Get
Return m_folderChangesets
End Get
Set(value As List(Of Changeset))
m_folderChangesets = value
End Set
End Property
Private m_folderChangesets As List(Of Changeset)