Repository navigation
Conversation
cached, blog-signed forward for the video stats endpoints
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 1 file.
1 file is newly checked for coverage.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes WOOA7S-2231
Proposed changes
Second consumer of connection's
Proxy_Controller(#53098), and the first step of VideoPress stage 2 (WOOA7S-2234): the package serves the data of its dashboard widgets from its own route, so it does not depend on the analytics dashboard for transport.The Top videos widget reads
stats/video-playsthrough the dashboard's proxy,/jetpack-premium-analytics/v1/proxy/v1.1/stats/video-plays. This PR gives VideoPress the same kind of route, so a client moves from one to the other by changing the base of the URL: same WordPress.com endpoint, same query params, same response.What VideoPress declares
Api_Proxy_Controlleris a table and two hooks. The table exposesstats/video-playsandstats/video/<id>onview_stats, withmanage_optionsalways accepted.init()runs onrest_api_initand builds the package'sProxy_Controllerfor/jetpack/v4/videopress/proxy/v<version>/<endpoint>, so the package class loads on REST requests only. The cache prefix joinsjetpack_stats_transient_cleanup_prefixesfrom the Initializer, where cron can see it.Allowlist, capability check, blog-signed forward, five-minute cache,
force_refreshand the error shapes come from connection and are tested there. The VideoPress tests cover what the table declares and nothing the package already tests: which endpoints route, who reads them, and the cache prefix.What does not change
The existing
/jetpack/v4/videopress/stats/video-playsroute and the Overview screen that reads it. No client calls the new route yet: the widget moves to it in a later step (WOOA7S-2233).Sites without the Stats module
The proxy forces no flags. On a site without the Stats module,
stats/video-playsneedscheck_stats_module=falsein the query.stats/video/<id>does not read that flag on WordPress.com, so it answers 404 there.Related product discussion/links
Linear: WOOA7S-2247 for the package, WOOA7S-2234 for the stage, WOOA7S-2231 for this step. Stacked on #53098.
Does this pull request change what data or activity we track or use?
No.
Testing instructions
jp test php packages/videopressOn a site connected to WordPress.com, with VideoPress active and some video plays, open the VideoPress dashboard and run in the browser console:
daysof the last seven days./jetpack-premium-analytics/v1/proxy/v1.1/stats/video-playsresolves with the same payload./jetpack/v4/videopress/proxy/v1.1/stats/video/<attachment id>?statType=all&period=day&num=7resolves with thefieldsanddataof that video./jetpack/v4/videopress/proxy/v1.1/stats/top-postsis rejected withrest_no_route.For the cache, run the first request twice and list the transients:
wp transient list --search='jetpack_videopress_proxy_*'One entry per distinct query. Adding
force_refresh=1to the query creates none.For the capability, repeat the first request as a user who holds
view_statsand is not an administrator: it resolves. As a user who holds neither, it is rejected with a 403.