TFS 2010 API - 迭代 QueryHistory 中返回的变更集列表太慢

发布于 2024-10-20 03:46:58 字数 512 浏览 10 评论 0原文

长话短说。分析后,此命令占用了处理量的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后咖啡店 2024-10-27 03:46:58

VersionControlServer.QueryHistory 的调用返回一个 IEnumerable,因此我假设它就像在 LINQ to Objects 中一样,并且在迭代 IEnumerable 后立即执行实际查询(关键字:延迟执行)。

您无法将结果分配给 List,因为返回值是 IEnumerable 的非泛型版本。对结果调用 Cast()OfType() 会返回通用的 IEnumerable 之后您可以调用 ToList() 并获取 ListToList() 迭代 IEnumerable,因此它类似于 foreach,并且占用大部分时间。

我提到的方法是扩展方法,位于 System.Linq 命名空间中。

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.

少女的英雄梦 2024-10-27 03:46:58

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.

北恋 2024-10-27 03:46:58

布尔值“包含更改”正在花费时间...如果您不包含更改而仅包含更改集的元数据,则查询速度非常快,

因此查询应如下所示:

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

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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文