Skip to content

Commit

Permalink
Merge branch 'AvoidListUsersThrottling' of https://github.com/KoenZom…
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenbe committed Oct 29, 2021
2 parents 088bff6 + 1abb481 commit dab5ffb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lib/PnP.Framework/Graph/UsersUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ public static Model.User GetUser(string accessToken, string userPrincipalName, s

IGraphServiceUsersCollectionPage pagedUsers;

pagedUsers = await graphClient.Users
.Request()
.Select(string.Join(",", propertiesToSelect))
.Filter(filter)
.OrderBy(orderby)
.GetAsync();
// Retrieve the first batch of users. 999 is the maximum amount of users that Graph allows to be trieved in 1 go. Use maximum size batches to lessen the chance of throttling when retrieving larger amounts of users.
pagedUsers = await graphClient.Users.Request()
.Select(string.Join(",", propertiesToSelect))
.Filter(filter)
.OrderBy(orderby)
.Top(!endIndex.HasValue ? 999 : endIndex.Value >= 999 ? 999 : endIndex.Value)
.GetAsync();

int pageCount = 0;
int currentIndex = 0;
Expand Down Expand Up @@ -188,6 +189,7 @@ public static Model.User GetUser(string accessToken, string userPrincipalName, s

if (pagedUsers.NextPageRequest != null && (!endIndex.HasValue || currentIndex < endIndex.Value))
{
// Retrieve the next batch of users. The possible oData instructions such as select and filter are already incorporated in the nextLink provided by Graph and thus do not need to be specified again.
pagedUsers = await pagedUsers.NextPageRequest.GetAsync();
}
else
Expand Down

0 comments on commit dab5ffb

Please sign in to comment.