Pager Total Pages

I have a process that iterates through some pages, and is taking around 40seconds. I’d like to display a progress indication, but I don’t have any way of knowing Pager.Pages.Count As I’m filtering by ObjectIds in my BatchGet() I thought I could estimate by knowing how many ObjectIds I had processed, but that doesn’t work either as the results aren’t sorted by ObjectId.

Iterating through all the pages first is majority of the time, so doesn’t work to do that to get count.

For an example

IEnumerable<string> classItemIds = classes.Select(c => c.SquareID);

Pager<InventoryChange> invChanges = await _client.Inventory.BatchGetChangesAsync(
	new BatchRetrieveInventoryChangesRequest()
	{
		CatalogObjectIds = classItemIds,
		LocationIds = [LocationId],
	});

await foreach (var page in invChanges.AsPagesAsync())
{
//Report back Page#/TotalPages
	foreach (var item in page.Items)
	{
...
    }
}

The Square API uses cursor-based pagination and doesn’t expose a total page/item count in responses. The Pager<T> only knows whether there’s a next page, not how many remain.

For progress indication, a couple of options:

• Track items processed against your input CatalogObjectIds.Count as an approximate denominator
• Show an indeterminate indicator with pages processed + elapsed time

That doesn’t work as the CatalogObjectIds are sorted by updated DateTime, not grouped.

I guess showing pages processed gives some arbitrary update, and possibly a speed (its going to be terrible on cellular connection I think).