You could use batch
to return several endpoints at once:
https://developer.wordpress.com/docs/api/1.1/get/batch/
However, instead of refreshing data for all 5,000 posts every hour, it might be best to only trigger an update when a post is actually visited. I assume that some of your old posts don’t get visits every day.
You could add the post ID to an array whenever it’s visited, and then query for stats for all post IDs in that array every hour. You could also refresh older posts once a day for example, and only do hourly queries for your most recent posts.
Another alternative would be to use the old WordPress.com Stats API. It allows you to query for multiple post IDs at once. You can find out more about it here:
https://stats.wordpress.com/csv.php
http://wpgr.org/2013/03/02/rendering-jetpack-stats/
I hope this helps.
Thank you. It works.
btw the batch method doesn’t let me use endpoint args. Like, when I try to select only data field from the post views endpoint it still loads all the data of post views endpoint call including author, blah blah and even post content. I think this slows down the response.
Any work around for this ?
Could you give me an example of the query you ran, so I can run some tests?
/batch/?urls[]=/sites/-removed-/stats/post/1234?fields=data&urls[]=/sites/-removed-/stats/post/2345?fields=data
Thanks! I was able to reproduce the issue. It seems the batch endpoint doesn’t support the fields
parameter yet. I took note of it, and we’ll get working on that.
I’ll post again here as soon as I have some news!