SharePoint【学习笔记】-- 使用ViewFields提升SPQuery查询性能

用SPquery查询文档库文件,当使用了Scope=\"Recursive\后,性能大幅下降,通过开发人员面板看到我的webpart查询数据耗时:EnsureListItemsData (196.45 ms)

在查询语句中加入ViewFields限制,只取需要用到的字段,查询时间能缩短将近一半:EnsureListItemsData (96.47 ms)

sPQuery.ViewFields = string.Concat(   

                    "<FieldRef Name='FileLeafRef' />",   

                    "<FieldRef Name='EncodedAbsUrl' />",   

                    "<FieldRef Name='Modified' />",   

                    "<FieldRef Name='File_x0020_Type' />",   

                    "<FieldRef Name='LinkTitle' />",   

                    "<FieldRef Name='ServerUrl' />",   

                    "<FieldRef Name='PermMask' />");                   

sPQuery.ViewFieldsOnly = true;

 

你可能感兴趣的:(SharePoint)