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 d开发者_JS百科irectly to a List<Changeset>
?
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.
QueryHistory lazy loads the collection. That is to say, that it doesn't actually execute your query until you try to iterate through it.
the boolean "include changes" is taking the time... If you do not include the changes and only the metadata of the changesets 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);
精彩评论