TFS 2010 API - Iterating through a list of change sets returned in QueryHistory is too slow

Shortly speaking. After profiling, this command takes 0.1% of the processing

var ChangesetList = TFSConnection.GetInstance().GetVersionControl().QueryHistory (Path, VersionSpec.Latest,0, RecursionType.Full, "", null, VersionSpec.Latest, Int32.MaxValue,true, false); 

This one, 65.7%. (funny thing, all processing inside consumes only 3%)

 foreach (Changeset changeset in ChangesetList) 

It takes a few seconds until I get my list ... What is happening? Why is this so repeated on the list so slowly?

Is there a faster way to do this?

Edit: Also, why can't I convert it directly to List<Changeset> ?

+4
source share
3 answers

Calling VersionControlServer.QueryHistory returns an IEnumerable , so I assume it looks like LINQ to Objects and the actual query is executed as soon as you iterate through IEnumerable (keyword: deferred execution).

You cannot assign a result to a list because the return value is not a generic version of IEnumerable . Calling Cast<Changeset>() or OfType<Changeset>() as a result returns a generic IEnumerable<Changeset>. . After that, you can call ToList() and get a List<Changeset> . ToList() over IEnumerable<T> , so it looks like foreach and takes most of the time.

The methods I described are extension methods and are located in the System.Linq namespace.

+10
source

QueryHistory lazy loads the collection. That is, it does not actually fulfill your request until you try to iterate through it.

+4
source

logical "included changes" take time ... If you do not include the changes and only the metadata of the change sets, the query is very fast

so the query should look like this:

 var ChangesetList = TFSConnection.GetInstance().GetVersionControl().QueryHistory (Path, VersionSpec.Latest,0, RecursionType.Full, "", null, VersionSpec.Latest, Int32.MaxValue,**false,** false); 
+1
source

Source: https://habr.com/ru/post/1341804/


All Articles