最近的项目中遇到了一个需求,需要向SharePointList 查询Item是否存在,找到了CamlQuery这样一个方法,但是没有找到使用这个接口的频率限制说明文档,于是就有了这篇随笔。
新接触这个方向,请大家多多指教。
#Load SharePoint CSOM Assemblies Add-Type -Path "F:Microsoft.SharePoint.Client.dll" Add-Type -Path "F:Microsoft.SharePoint.Client.Runtime.dll" Add-Type -Path "F:Microsoft.SharePoint.Client.Publishing.dll" #Variables for Processing $SiteUrl = "<app web url>" $ListName="<ListTitle>" $UserName="<account>" $Password ="<password>" #Setup Credentials to connect $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force)) #Set up the context $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) $Context.Credentials = $credentials $List = $Context.web.Lists.GetByTitle('<ListTitle>') $Title="Test" $start = Get-Date for($i=0;$i -le 1000;$i++) { try { $Query = New-Object Microsoft.SharePoint.Client.CamlQuery; $Query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>"+$Title+"</Value></Eq></Where></Query></View>" $ListItems = $list.GetItems($Query); $Context.Load($ListItems) $Context.ExecuteQuery() $midend = Get-Date write-host "Test"+$i+"Do"+($midend - $start).TotalSeconds "Test"+$i+"Do"+($midend - $start).TotalSeconds | Out-File -Append d:PsTest.txt } catch [System.Exception] { $midend = Get-Date # write-host "Test"$i "Error" ($midend - $start).TotalSeconds "Test"+$i+"Error"+($midend - $start).TotalSeconds | Out-File -Append d:PsTest.txt write-host -f red $_.Exception.ToString() } } $end = Get-Date write-host "Test"$i "Console"($end - $start).TotalSeconds "Test"+$i+"Console"+($end - $start).TotalSeconds| Out-File -Append d:PsTest.txt
根据返回的结果统计来看,1000次顺序Query请求成功率为100%,曲线如下
1000次的Query查询大概用时238.46秒,曲线中纵轴为响应的返回时间,整体看来曲线还不错,回来进行一下并行测试的的情况。