Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS 2010 API - Iterating through list of changesets returned in QueryHistory is way too slow

Long story short. 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 the processing inside consumes only 3%)

foreach (Changeset changeset in ChangesetList)

It takes several seconds until I get my list... What is happening? Why is it so slow iterating through the list?

Is there any faster way to do this ?

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

like image 431
Conrad Clark Avatar asked Dec 06 '22 23:12

Conrad Clark


1 Answers

The call to VersionControlServer.QueryHistory returns an IEnumerable, so I assume it's like in LINQ to Objects and the actual query is executed as soon as you iterate over the IEnumerable (keyword: deferred execution).

You can't assign the result to an List because the return value is the non generic Version of IEnumerable. Calling Cast<Changeset>() or OfType<Changeset>() on the result returns a generic IEnumerable<Changeset>. After that you can call ToList() and get a List<Changeset>. ToList() iterates over the IEnumerable<T> so it's like the foreach and takes most of the time.

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

like image 199
marste Avatar answered Jan 01 '23 12:01

marste