以最快的方式获取大型共享点列表的项目计数
我正在尝试以编程方式获取共享点文档库中的项目计数。我正在使用的规模是 30-70000 个项目。我们在智能部分中有用户控件来显示计数。我们的网站是一个团队网站。
这是获取总计数的代码:
SPList VoulnterrList = web.Lists[ListTitle];
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope=\"Recursive\"";
string queries = "<Where><Eq><FieldRef Name='ApprovalStatus' /><Value Type='Choice'>Pending</Value></Eq></Where>";
query.Query = queries;
SPListItemCollection lstitemcollAssoID = VoulnterrList.GetItems(query);
lblCount.Text = "Total Proofs: " + VoulnterrList.Items.Count.ToString() + " Pending Proofs: " + lstitemcollAssoID.Count.ToString();
问题是这存在严重的性能问题,加载页面需要 75 到 80 秒。如果我们评论此页面加载时间将减少到 4 秒。解决这个问题的任何更好的方法
我们的方法是 sharepoint 2007
I am trying to get the count of the items in a sharepoint document library programatically. The scale I am working with is 30-70000 items. We have usercontrol in a smartpart to display the count . Ours is a TEAM site.
This is the code to get the total count:
SPList VoulnterrList = web.Lists[ListTitle];
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope=\"Recursive\"";
string queries = "<Where><Eq><FieldRef Name='ApprovalStatus' /><Value Type='Choice'>Pending</Value></Eq></Where>";
query.Query = queries;
SPListItemCollection lstitemcollAssoID = VoulnterrList.GetItems(query);
lblCount.Text = "Total Proofs: " + VoulnterrList.Items.Count.ToString() + " Pending Proofs: " + lstitemcollAssoID.Count.ToString();
The problem is this has serious performance issue it takes 75 to 80 sec to load the page. if we comment this page load will decrees to 4 sec. Any better approch for this problem
Ours is sharepoint 2007
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
VoulnterrList.ItemCount
而不是VoulnterrList.Items.Count
。使用 List.Items 时,将从内容数据库加载列表中的所有项目。由于我们实际上并不需要这些项目来获取计数,因此这是浪费的开销。
这将修复第 8 行的性能,但根据查询返回的结果数量,您可能仍会在第 9 行遇到问题。
Use
VoulnterrList.ItemCount
instead ofVoulnterrList.Items.Count
.When List.Items is used, all items in the list are loaded from the content database. Since we don't actually need the items to get the count this is wasted overhead.
This will fix performance at line 8, but you may still have issues at line 9 depending on the number of results returned by the query.
您可以在此处进行两项优化:
在列表的某一列上创建索引
在
中使用该列CAML 查询的
部分,以便仅检索该索引列。这应该会加快。有关如何在列上创建索引的信息,请参阅这篇文章:
http://sharepoint.microsoft.com/Blogs/GetThePoint /Lists/Posts/Post.aspx?ID=162
You can do two optimizations here:
Create an index on one of the column of your list
Use that column in
<ViewFields>
section of your CAML query so that only that indexed column is retrieved.This should speed up. See this article on how to create index on column:
http://sharepoint.microsoft.com/Blogs/GetThePoint/Lists/Posts/Post.aspx?ID=162