diff --git a/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs b/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs index 572dad56..1f0ba57f 100644 --- a/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs @@ -112,7 +112,7 @@ public async Task GetAllAsync() var apiKeys = new ApiKeys(client); // Act - var result = await apiKeys.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + var result = await apiKeys.GetAllAsync(cancellationToken: CancellationToken.None).ConfigureAwait(false); // Assert mockHttp.VerifyNoOutstandingExpectation(); diff --git a/Source/StrongGrid/Extensions/Public.cs b/Source/StrongGrid/Extensions/Public.cs index 9c31cb98..064cd511 100644 --- a/Source/StrongGrid/Extensions/Public.cs +++ b/Source/StrongGrid/Extensions/Public.cs @@ -1150,14 +1150,20 @@ public static Task UpdateAsync(this ISegments segments, string segmentI /// public static async Task GetUnassignedAsync(this IIpAddresses ipAddresses, CancellationToken cancellationToken = default) { - var allIpAddresses = await ipAddresses.GetAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false); + var unassignedIpAddresses = new List(); + var currentOffset = 0; - var unassignedIpAddresses = allIpAddresses.Records - .Where(ip => ip.Pools == null || !ip.Pools.Any()) - .ToArray(); + while (true) + { + var allIpAddresses = await ipAddresses.GetAllAsync(limit: Utils.MaxSendGridPagingLimit, offset: currentOffset, cancellationToken: cancellationToken).ConfigureAwait(false); + unassignedIpAddresses.AddRange(allIpAddresses.Where(ip => ip.Pools == null || !ip.Pools.Any())); - return unassignedIpAddresses; - } + if (allIpAddresses.Length < Utils.MaxSendGridPagingLimit) break; + currentOffset += Utils.MaxSendGridPagingLimit; + } + + return unassignedIpAddresses.ToArray(); + } } } diff --git a/Source/StrongGrid/Utilities/Utils.cs b/Source/StrongGrid/Utilities/Utils.cs index 88a05a84..e44e541c 100644 --- a/Source/StrongGrid/Utilities/Utils.cs +++ b/Source/StrongGrid/Utilities/Utils.cs @@ -11,6 +11,8 @@ internal static class Utils { private static readonly byte[] Secp256R1Prefix = Convert.FromBase64String("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE"); + public const int MaxSendGridPagingLimit = 500; + public static RecyclableMemoryStreamManager MemoryStreamManager { get; } = new RecyclableMemoryStreamManager(); ///