使用ViewFields提升SPQuery查询性能
<div id="cnblogs_post_body"> 用SPquery查询文档库文件,当使用了Scope=\&quot;Recursive\后,性能大幅下降,通过开发人员面板看到我的webpart查询数据耗时:EnsureListItemsData (196.45 ms)在查询语句中加入ViewFields限制,只取需要用到的字段,查询时间能缩短将近一半:EnsureListItemsData (96.47 ms)
<div id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"> 1: sPQuery.ViewFields = string.Concat( 2: &quot;<FieldRef Name='FileLeafRef' />&quot;, 3: &quot;<FieldRef Name='EncodedAbsUrl' />&quot;, 4: &quot;<FieldRef Name='Modified' />&quot;, 5: &quot;<FieldRef Name='File_x0020_Type' />&quot;, 6: &quot;<FieldRef Name='LinkTitle' />&quot;, 7: &quot;<FieldRef Name='ServerUrl' />&quot;, 8: &quot;<FieldRef Name='PermMask' />&quot;); 9: sPQuery.ViewFieldsOnly = true;
页:
[1]