使用ViewFields提升SPQuery查询性能

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

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

   1: sPQuery.ViewFields = string.Concat(
   2:                    "<FieldRef Name='FileLeafRef' />",
   3:                    "<FieldRef Name='EncodedAbsUrl' />",
   4:                    "<FieldRef Name='Modified' />",
   5:                    "<FieldRef Name='File_x0020_Type' />",
   6:                    "<FieldRef Name='LinkTitle' />",
   7:                    "<FieldRef Name='ServerUrl' />",
   8:                    "<FieldRef Name='PermMask' />");                
   9: sPQuery.ViewFieldsOnly = true;

你可能感兴趣的:(query)