diff --git a/inc/Engine/Media/Fonts/Frontend/Controller.php b/inc/Engine/Media/Fonts/Frontend/Controller.php index a3af1199fc..c04b533783 100644 --- a/inc/Engine/Media/Fonts/Frontend/Controller.php +++ b/inc/Engine/Media/Fonts/Frontend/Controller.php @@ -70,6 +70,9 @@ public function rewrite_fonts( $html ): string { return $html; } + // For test purposes. + $start_time = microtime( true ); + $html_nocomments = $this->hide_comments( $html ); $v1_fonts = $this->find( '])+)?(?:\s+href\s*=\s*([\'"])(?(?:https?:)?\/\/fonts\.googleapis\.com\/css[^\d](?:(?!\1).)+)\1)(?:\s+[^>]*)?>', $html_nocomments ); @@ -80,6 +83,11 @@ public function rewrite_fonts( $html ): string { return $html; } + // Count fonts - for test purposes. + $total_v1 = count( $v1_fonts ); + $total_v2 = count( $v2_fonts ); + $total_fonts = $total_v1 + $total_v2; + foreach ( $v1_fonts as $font ) { $html = $this->replace_font( $font, $html ); } @@ -92,6 +100,13 @@ public function rewrite_fonts( $html ): string { $html = $this->remove_preconnect_and_prefetch( $html ); } + // End time measurement. + $end_time = microtime( true ); + + // Log the total execution time and number of fonts processed, with breakdown. + $duration = $end_time - $start_time; + Logger::debug( "Total execution time for Host Google Fonts Feature in seconds -- $duration. Fonts processed: $total_fonts | Total v1: $total_v1 | Total v2: $total_v2", [ 'Host Fonts Locally' ] ); + return $html; } diff --git a/tests/Integration/inc/Engine/Media/Fonts/Frontend/Subscriber/rewriteFonts.php b/tests/Integration/inc/Engine/Media/Fonts/Frontend/Subscriber/rewriteFonts.php index b1c5826163..2f55998ed4 100644 --- a/tests/Integration/inc/Engine/Media/Fonts/Frontend/Subscriber/rewriteFonts.php +++ b/tests/Integration/inc/Engine/Media/Fonts/Frontend/Subscriber/rewriteFonts.php @@ -45,7 +45,7 @@ public function testShouldReturnAsExpected( $config, $expected ) { $this->assertSame( $expected['html'], - apply_filters( 'rocket_buffer', $config['html'] ) // @phpstan-ignore-line + wpm_apply_filters_typed('string', 'rocket_buffer', $config['html']) ); }