Skip to content

Commit

Permalink
Boost: Deduplicate cornerstone URLs from other providers (#40289)
Browse files Browse the repository at this point in the history
* Remove cornerstone urls from other providers

* changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11954991287

Upstream-Ref: Automattic/jetpack@2bc0e23
  • Loading branch information
donnchawp authored and matticbot committed Nov 21, 2024
1 parent 47519ff commit 2560cbc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/lib/critical-css/source-providers/Source_Providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ public function get_current_critical_css_key() {
* @return array
*/
public function get_provider_sources( $context_posts = array() ) {
$sources = array();
$sources = array();
$flat_core_and_cornerstone_urls = array();

$wp_core_provider_urls = WP_Core_Provider::get_critical_source_urls( $context_posts );
$flat_wp_core_urls = array();
foreach ( $wp_core_provider_urls as $urls ) {
$flat_wp_core_urls = array_merge( $flat_wp_core_urls, $urls );
$flat_core_and_cornerstone_urls = array_merge( $flat_core_and_cornerstone_urls, $urls );
}
$cornerstone_provider_urls = Cornerstone_Provider::get_critical_source_urls( $context_posts );
foreach ( $cornerstone_provider_urls as $urls ) {
$flat_core_and_cornerstone_urls = array_merge( $flat_core_and_cornerstone_urls, $urls );
}
$flat_core_and_cornerstone_urls = array_values( array_unique( $flat_core_and_cornerstone_urls ) );

foreach ( $this->get_providers() as $provider ) {
$provider_name = $provider::get_provider_name();
Expand All @@ -138,10 +143,10 @@ public function get_provider_sources( $context_posts = array() ) {
continue;
}

// This removes the home and blog pages from the list of pages,
// This removes core and cornerstone URLs from the list of URLs,
// so they don't belong to two separate groups.
if ( ! in_array( $provider, array( WP_Core_Provider::class, Cornerstone_Provider::class ), true ) ) {
$urls = array_values( array_diff( $urls, $flat_wp_core_urls ) );
$urls = array_values( array_diff( $urls, $flat_core_and_cornerstone_urls ) );
}

if ( empty( $urls ) ) {
Expand Down

0 comments on commit 2560cbc

Please sign in to comment.