As noted on #26708 and p8F9tW-RX-p2, there are a lot of customers that would like to see the view counts on the Blog Posts list brought back.
@Automattic/tanooki is looking into bringing back this functionality (or similar functionality) with a less resource-intensive implementation that delivers better performance for both customers' devices and our servers. There are some possible options to explore mentioned on p8F9tW-RX-p2.
If performance constraints necessitate a change from the original experience, this issue will be updated accordingly.
Before:
After:
1.
2.
3.
4.
After pairing with @creativecoder to dig into possible approaches, we've come up with a plan forward.
^ I'll update the tasks with the above.
*There seems to be a bug with the way historical post views are queried from the post views endpoint. They're correctly queried in the top posts endpoint, which explains a large part of the performance difference between the two in terms of response time. We're hoping that updating the post views endpoint to use the same method will significantly cut down on the 1 month views request time. If that doesn't work, we don't really have a way forward b/c our options all have significant compromises (i.e. showing view data that doesn't include the current day, or only being able to query an insignificant period of views data for each post).
@michaeldcain and I have dug into the code and further developed this plan for supporting post list views with the API:
(As stated above), instead of displaying all views for a post, we'll display "Recent views". This will use the post views endpoint (/sites/%s/stats/post/%d
), as before, but with the following changes:
Modify the endpoint to get a summary of the data. All we need here is the views for the post, not any other details.
Generate the number of views for each post in the last 30 days.
(TBD, still researching this) Modify the API call so that we can batch view summary results for multiple posts, rather than needing a separate request for each post.
@jmdodd Please let us know your questions, concerns, or suggestions. Thanks!
If you are interested in cutting down on network requests, there is a batch endpoint that we use for likes: https://developer.wordpress.com/docs/api/1.1/get/batch/
I'd like to make a case for fetching views for multiple posts from a single database query; batching on a stats
endpoint with a new post_ids
parameter would cut down on both network and database queries.
Note: updated task list in description to reflect our plan to use a new "posts views" endpoint.
Here's an initial design for a "post views" endpoint to support this feature.
Url: https://public-api.wordpress.com/rest/v1.1/sites/$site/stats/post-views
Query params
context
, http_envelope
, pretty
, meta
, fields
, callback
post_ids=1,2,3
specify which posts to query by iddate=YYYY-MM-DD
most recent day to include in results, default: todaynum=30
number of periods to get, default: 1period=day|week|month|year
which period to use for date range, default: dayoffset=-4
number of hours from GMT, default: site's offsetResponse params
"date": "YYYY-MM-DD"
end date"posts": [ { "ID": 1, "views": 20 } ]
array of posts with id and views@jmdodd I copied the num
and period
parameters from some of the other stats endpoints, like video-plays
and country-views
. Maybe period
isn't appropriate if we are limiting the number of queries for each post. What is a reasonable maximum number of days? What about for post ids?
Let's start with a simple period = day, num = 30, maximum number = 30 for testing; this can be expanded later as long as we continue to use post_ids
to batch things reasonably.
https://github.com/Automattic/wp-calypso/pull/27090 is under review.
This issue has been satisfactorily addressed. Accepting this!
Most helpful comment
Here's an initial design for a "post views" endpoint to support this feature.
Url:
https://public-api.wordpress.com/rest/v1.1/sites/$site/stats/post-views
Query params
context
,http_envelope
,pretty
,meta
,fields
,callback
post_ids=1,2,3
specify which posts to query by iddate=YYYY-MM-DD
most recent day to include in results, default: todaynum=30
number of periods to get, default: 1period=day|week|month|year
which period to use for date range, default: dayoffset=-4
number of hours from GMT, default: site's offsetResponse params
"date": "YYYY-MM-DD"
end date"posts": [ { "ID": 1, "views": 20 } ]
array of posts with id and views@jmdodd I copied the
num
andperiod
parameters from some of the other stats endpoints, likevideo-plays
andcountry-views
. Maybeperiod
isn't appropriate if we are limiting the number of queries for each post. What is a reasonable maximum number of days? What about for post ids?