最近的項目中遇到了一個需求,須要向SharePointList 查詢Item是否存在,找到了CamlQuery這樣一個方法,可是沒有找到使用這個接口的頻率限制說明文檔,因而就有了這篇隨筆。web
新接觸這個方向,請你們多多指教。app
#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%,曲線以下ide
1000次的Query查詢大概用時238.46秒,曲線中縱軸爲響應的返回時間,總體看來曲線還不錯,回來進行一下並行測試的的狀況。測試