[英]Microsoft Graph API - Timeout while getting list of items in Sharepoint Document Library (C# ASP DotNet)
I'm using Microsoft Graph API to get a list of documents in a Sharepoint Document Library.我正在使用 Microsoft Graph API 获取 Sharepoint 文档库中的文档列表。 Code was fine for 6 months.代码可以使用 6 个月。 Last Friday my code broke.上周五我的密码坏了。
There are about 700 documents in the library, and in the past the request would complete after 5-6 seconds.库中大约有 700 个文档,过去请求会在 5-6 秒后完成。 As of last Friday (23/09/2022) it started timing out after (~120 seconds).截至上周五(2022 年 9 月 23 日),它开始超时(约 120 秒)。 If I limit it to 200 rows, it works after 12 seconds, but I need all 700, If there is a way to do paging that could work.如果我将它限制为 200 行,它会在 12 秒后工作,但我需要所有 700 行,如果有一种方法可以进行分页。 then I could make my own method.然后我可以制定自己的方法。 Also if I could increase the timeout it might work - I have tried modifying both the GraphClient.HttpProvider.OverallTimeout and the request,WithMaxRetry to 900 seconds.另外,如果我可以增加超时时间,它可能会起作用——我尝试将 GraphClient.HttpProvider.OverallTimeout 和请求 WithMaxRetry 修改为 900 秒。 but it still times out after around 122 seconds.但它仍然在大约 122 秒后超时。
Here is the relevant part of my code (rowLimit is an int set to 5000):这是我的代码的相关部分(rowLimit 是一个设置为 5000 的整数):
List<QueryOption> queryOptions = new List<QueryOption>()
{
new QueryOption("Top", $"{rowLimit}"),
new QueryOption ("Prefer","allowthrottleablequeries")
};
IDriveItemChildrenCollectionPage result = await GraphClient.Sites[siteID].Drives[documentLibraryID].Root.Children
.Request(queryOptions)
.Expand("listItem")
.WithMaxRetry(1) //set 1 max retry and set timeout
.WithMaxRetry(TimeSpan.FromSeconds(900)
.GetAsync();
After ~122 seconds I receive the following exception: Code: tooManyRetries Message: More than 1 retries encountered while sending the request. ~122 秒后,我收到以下异常:代码:tooManyRetries 消息:发送请求时重试次数超过 1 次。
As mentioned, I can get it to work if I limit the number of rows - 200 rows return in around 12 seconds, 400 rows return in around 24 seconds.如前所述,如果我限制行数,我可以让它工作——200 行在大约 12 秒内返回,400 行在大约 24 秒内返回。 The strange thing is it was fine last week, so perhaps Microsoft changed something?奇怪的是上周还不错,所以也许微软改变了什么?
I managed to work around my issue by using pagination:我设法通过使用分页来解决我的问题:
List<DriveItem> allItems = new();
var result = await GraphClient.Sites[siteID].Drives[documentLibraryID].Root.Children
.Request()
.Expand("listItem")
.Top(100)
.GetAsync();
var pageIterator = PageIterator<DriveItem>
.CreatePageIterator(
GraphClient,
result,
(item) =>
{
allItems.Add(item);
return true;
});
await pageIterator.IterateAsync();
This way I get the results 100 at a time, which was within the timeout threshold.这样我一次得到 100 个结果,这在超时阈值内。 They are then all added to a List (allItems) so I didn't need to change the rest of my code.然后将它们全部添加到列表 (allItems) 中,因此我不需要更改代码的 rest。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.