Skip to content

Commit

Permalink
(GH-368) Remove 'limit' and 'offset' from IpAddresses.GetUnassignedAs…
Browse files Browse the repository at this point in the history
…ync in order to be consistent with the signature of the GetAssignedAsync method
  • Loading branch information
Jericho committed Jan 14, 2022
1 parent 9c362b6 commit bca65f5
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Source/StrongGrid/Extensions/Public.cs
Expand Up @@ -1150,9 +1150,9 @@ public static Task<Segment> UpdateAsync(this ISegments segments, string segmentI
/// <returns>
/// An array of <see cref="IpAddress">Ip addresses</see>.
/// </returns>
public static async Task<IpAddress[]> GetUnassignedAsync(this IIpAddresses ipAddresses, int limit = 10, int offset = 0, CancellationToken cancellationToken = default)
public static async Task<IpAddress[]> GetUnassignedAsync(this IIpAddresses ipAddresses, CancellationToken cancellationToken = default)
{
var unassignedIpAddresses = new List<IpAddress>(limit);
var unassignedIpAddresses = new List<IpAddress>();
var currentOffset = 0;

while (true)
Expand All @@ -1163,20 +1163,14 @@ public static async Task<IpAddress[]> GetUnassignedAsync(this IIpAddresses ipAdd
// Take the addresses that have not been added to a pool
unassignedIpAddresses.AddRange(allIpAddresses.Where(ip => ip.Pools == null || !ip.Pools.Any()));

// Stop if we have enough unassigned addresses
if (unassignedIpAddresses.Count >= offset + limit) break;

// Stop if there are no more addresses to fetch
if (allIpAddresses.Length < Utils.MaxSendGridPagingLimit) break;

// Increase the offset so we retrieve the next set of 500 addresses
currentOffset += Utils.MaxSendGridPagingLimit;
}

return unassignedIpAddresses
.Skip(offset)
.Take(limit)
.ToArray();
return unassignedIpAddresses.ToArray();
}
}
}

0 comments on commit bca65f5

Please sign in to comment.