RocketCDN free tier - Frontend#8288
RocketCDN free tier - Frontend#8288wordpressfan wants to merge 20 commits intofeature/rocket-cdn-free-tierfrom
Conversation
Up to standards ✅🟢 Issues
|
| Category | Results |
|---|---|
| Documentation | 1 minor |
🟢 Metrics 9 complexity · 0 duplication
Metric Results Complexity 9 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
This PR implements frontend RocketCDN free-tier behavior by introducing a driver/strategy layer that decides whether CDN URL rewriting should happen for the current page (free: only whitelisted pages; paid/custom: rewrite broadly with page exclusions as applicable). It also simplifies CDN driver resolution to rely directly on the cdn_type option instead of the RocketCDN API.
Changes:
- Added CDN “drivers” (free/paid/custom) and a factory to decide rewrite eligibility per request.
- Updated CDN Subscriber to consult the resolved driver before rewriting URLs.
- Simplified
CDN\Context::get_driver()to return thecdn_typeoption value; updated unit fixtures/tests accordingly.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
inc/Engine/CDN/ServiceProvider.php |
Registers driver services, driver factory, and injects resolved driver into the CDN subscriber. |
inc/Engine/CDN/Subscriber.php |
Adds driver gating (should_rewrite_url) to allow/deny rewriting on a per-page basis. |
inc/Engine/CDN/Context.php |
Simplifies driver resolution to depend on cdn_type. |
inc/Engine/CDN/Drivers/DriverInterface.php |
Defines the driver contract (should_rewrite_url). |
inc/Engine/CDN/Drivers/DriverFactory.php |
Creates the active driver based on CDN\Context. |
inc/Engine/CDN/Drivers/RocketCDNFree.php |
Implements free-tier behavior: only rewrite on pages found in RocketCDN DB table. |
inc/Engine/CDN/Drivers/RocketCDNPaid.php |
Implements paid-tier behavior: rewrite unless URL matches excluded pages patterns. |
inc/Engine/CDN/Drivers/Custom.php |
Custom CDN driver (currently unconditional rewrite). |
inc/Engine/CDN/RocketCDN/Database/Queries/RocketCDN.php |
Adds is_url_found() helper for free-tier page lookup. |
inc/Engine/Optimization/UrlTrait.php |
Adds get_current_url() helper used by the CDN subscriber to evaluate the current page URL. |
tests/Unit/inc/Engine/CDN/Context/getDriver.php |
Updates unit test for the new Context constructor/signature and behavior. |
tests/Fixtures/inc/Engine/CDN/Context/getDriver.php |
Updates fixtures to reflect cdn_type-based driver resolution. |
phpstan-baseline.neon |
Updates baseline ignores (currently appears out of sync with the actual code in a couple places). |
Agent-Logs-Url: https://github.com/wp-media/wp-rocket/sessions/99ca5e7d-64e9-4539-9480-163a8475a550 Co-authored-by: wordpressfan <146129302+wordpressfan@users.noreply.github.com>
… methods Agent-Logs-Url: https://github.com/wp-media/wp-rocket/sessions/99ca5e7d-64e9-4539-9480-163a8475a550 Co-authored-by: wordpressfan <146129302+wordpressfan@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…ure/8263-frontend # Conflicts: # tests/Unit/inc/Engine/CDN/Subscriber/maybeReplaceUrl.php # tests/Unit/inc/Engine/CDN/Subscriber/rewrite.php # tests/Unit/inc/Engine/CDN/Subscriber/rewriteSrcset.php
… files Agent-Logs-Url: https://github.com/wp-media/wp-rocket/sessions/4a2c199b-dd4f-45ea-8045-dd0e658140c9 Co-authored-by: wordpressfan <146129302+wordpressfan@users.noreply.github.com>
… DriverFactory Agent-Logs-Url: https://github.com/wp-media/wp-rocket/sessions/78df7889-23cc-4d9b-a03d-93ef640286c8 Co-authored-by: wordpressfan <146129302+wordpressfan@users.noreply.github.com>
jeawhanlee
left a comment
There was a problem hiding this comment.
Great Job! I love the implementation
| * @return bool | ||
| */ | ||
| public function should_rewrite_url( string $url ): bool { | ||
| return $this->query->is_url_found( $url ); |
There was a problem hiding this comment.
I believe here we need to also factor that the homepage could be added but subscription creation would not have resolved on the website.
There was a problem hiding this comment.
we will consider having this in API, let me find a common way to handle this not to handle everything in the API GH issue.
There was a problem hiding this comment.
Need to update the file name to our naming convention
There was a problem hiding this comment.
Need to update the file name to our naming convention
| - | ||
| message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" | ||
| count: 1 | ||
| count: 2 |
There was a problem hiding this comment.
This is a good opportunity to update
to usewpm_apply_filters_typed instead of increasing the count. WDYT?
| $cdn_type = (string) $this->options->get( 'cdn_type', self::ROCKETCDN_TYPE ); | ||
|
|
||
| if ( self::ROCKETCDN_TYPE !== $cdn_type ) { | ||
| return self::BYOCDN_TYPE; | ||
| } | ||
|
|
||
| return $this->rocketcdn_resolver(); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves RocketCDN to either free or paid type. | ||
| * | ||
| * @return string | ||
| */ | ||
| private function rocketcdn_resolver(): string { | ||
| $subscription = $this->api_client->get_subscription_data(); | ||
|
|
||
| if ( empty( $subscription['is_active'] ) || 'running' !== $subscription['subscription_status'] ) { | ||
| return self::ROCKETCDN_FREE_TYPE; | ||
| } | ||
|
|
||
| return self::ROCKETCDN_PAID_TYPE; |
There was a problem hiding this comment.
On a second thought, we should preserve this logic, the cdn_type should really hold 2 types of driver (byocdn or rocketcdn) we don't care if rocketcdn is free or paid, it's still rocketcdn.
The rocketcdn resolve would resolve if it's free or pro, we will not be sending request to the API for this, we can access the data from the transient.
There was a problem hiding this comment.
I removed this part because we still don't know the final implementation for this in API side because we will mainly have the plan inside subscription status endpoint which is a new endpoint not the website search one that we use right now so we will save those data also in transient, I didn't want to have a code that is not needed for this PR and don't know if it's needed for next PRs or not.
Description
Fixes #8263
Apply CDN on frontend assets:
Type of change
Detailed scenario
What was tested
The three cases mentioned above.
How to test
To simulate cdn type u need to use one of the following snippets:
RocketCDN paid:
RocketCDN free:
Custom CDN:
For pages exclusions use the following snippet for RocketCDN paid and Custom CDN to apply exclusions (make sure to clear cache after enabling the snippet or changing on it):
Affected Features & Quality Assurance Scope
RocketCDN free tier.
Technical description
Documentation
cdn_typeto decide which one is enabled instead of depending on the API until we have the API ready.New dependencies
N/A
Risks
N/A
Mandatory Checklist
Code validation
Code style
Unticked items justification
If some mandatory items are not relevant, explain why in this section.
Additional Checks