TFS 2010 API - 迭代 QueryHistory 中返回的变更集列表太慢
长话短说。分析后,此命令占用了处理量的 0.1%
var ChangesetList = TFSConnection.GetInstance().GetVersionControl().QueryHistory
(Path, VersionSpec.Latest,0, RecursionType.Full, "", null,
VersionSpec.Latest, Int32.MaxValue,true, false);
,即 65.7%。 (有趣的是,里面的所有处理只消耗了 3%)
foreach (Changeset changeset in ChangesetList)
我需要几秒钟才能得到我的列表...... 怎么了?为什么遍历列表的速度这么慢?
有没有更快的方法来做到这一点?
编辑:另外,为什么我不能将其直接转换为 List
?
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>
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对
VersionControlServer.QueryHistory
的调用返回一个IEnumerable
,因此我假设它就像在 LINQ to Objects 中一样,并且在迭代 IEnumerable 后立即执行实际查询(关键字:延迟执行)。您无法将结果分配给 List,因为返回值是
IEnumerable
的非泛型版本。对结果调用Cast()
或OfType()
会返回通用的IEnumerable。
之后您可以调用ToList()
并获取List
。ToList()
迭代IEnumerable
,因此它类似于 foreach,并且占用大部分时间。我提到的方法是扩展方法,位于 System.Linq 命名空间中。
The call to
VersionControlServer.QueryHistory
returns anIEnumerable
, 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
. CallingCast<Changeset>()
orOfType<Changeset>()
on the result returns a genericIEnumerable<Changeset>.
After that you can callToList()
and get aList<Changeset>
.ToList()
iterates over theIEnumerable<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 延迟加载集合。也就是说,在您尝试迭代查询之前,它实际上不会执行您的查询。
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: