Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #7161: Host Google Fonts - Measure time #7163

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/Engine/Common/AbstractFileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function hash_to_path( string $hash ): string {
*
* @param int $levels Number of levels.
*/
$levels = apply_filters( 'rocket_used_css_dir_level', 3 );
$levels = wpm_apply_filters_typed( 'integer', 'rocket_used_css_dir_level', 3 );

$base = substr( $hash, 0, $levels );
$remain = substr( $hash, $levels );
Expand Down
15 changes: 15 additions & 0 deletions inc/Engine/Media/Fonts/Frontend/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])(?<url>(?:https?:)?\/\/fonts\.googleapis\.com\/css[^\d](?:(?!\1).)+)\1)(?:\s+[^>]*)?>', $html_nocomments );
Expand All @@ -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 );
}
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testShouldReturnAsExpected( $config, $expected ) {

$this->assertSame(
$expected['html'],
apply_filters('rocket_buffer', $config['html'])
wpm_apply_filters_typed('string', 'rocket_buffer', $config['html'])
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testShouldDoExpected( $config, $original, $expected ) {
->andReturn( $config['write'] );
$this->fonts_filesystem->shouldReceive( 'hash_to_path' )
->andReturnUsing( function( $hash ) {
$levels = apply_filters( 'rocket_used_css_dir_level', 3 );
$levels = wpm_apply_filters_typed('integer', 'rocket_used_css_dir_level', 3 );

$base = substr( $hash, 0, $levels );
$remain = substr( $hash, $levels );
Expand Down
Loading