If you just want the total, don't bother paging through the entire full result set.
Use the total
property of the Common Wrapper Object. This will save lots of time and bandwidth and quota and doesn't require you to loop through the results just to count things.
The total
property is not enabled by default, so you will need to Create a custom filter for your queries. (You should do this anyway, to speed your app up.)
Here's how it looks for that /users/{ids}/answers
route:
/users/2440312/answers?site=stackoverflow&filter=!.UE8F0_EMkjmCAGv
Which currently yields:
{
"has_more": false,
"quota_max": 10000,
"quota_remaining": 9993,
"page": 1,
"page_size": 30,
"total": 41,
"type": "answer"
}
Unfortunately, the API does not do subtotals. So if you fetch more than one user at a time, this streamlined method will not work. (EG: this two-user request yields total
= 3663 (at least 37 pages of answers) with no way to tell which user has which without paging through your original-style query.)