From a021eeebd54d4fad030cc88ee6b064561a5e1052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 11:11:45 -0500 Subject: [PATCH 1/4] update context --- inc/Engine/Media/Fonts/Frontend/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Frontend/Controller.php b/inc/Engine/Media/Fonts/Frontend/Controller.php index c04b533783..07e9788b25 100644 --- a/inc/Engine/Media/Fonts/Frontend/Controller.php +++ b/inc/Engine/Media/Fonts/Frontend/Controller.php @@ -105,7 +105,7 @@ public function rewrite_fonts( $html ): string { // 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' ] ); + Logger::debug( "Total execution time for Host Google Fonts Feature in seconds -- $duration. CSS files processed: $total_fonts | Total v1: $total_v1 | Total v2: $total_v2", [ 'Host Fonts Locally' ] ); return $html; } From fbc7af6ab4c76c99de9fba267d4fa7f9dbd40b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 11:12:04 -0500 Subject: [PATCH 2/4] add log for number of fonts downloaded, download time and average --- inc/Engine/Media/Fonts/Filesystem.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/inc/Engine/Media/Fonts/Filesystem.php b/inc/Engine/Media/Fonts/Filesystem.php index f26c834277..105212f981 100644 --- a/inc/Engine/Media/Fonts/Filesystem.php +++ b/inc/Engine/Media/Fonts/Filesystem.php @@ -84,6 +84,9 @@ public function write_font_css( string $font_url, string $provider ): bool { $font_urls = $matches[1]; $local_css = $css_content; + $count_fonts = 0; + $download_average = 0; + foreach ( $font_urls as $font_url ) { $font_path = wp_parse_url( $font_url, PHP_URL_PATH ); @@ -99,6 +102,7 @@ public function write_font_css( string $font_url, string $provider ): bool { } if ( ! $this->filesystem->exists( $local_path ) ) { + $download_start = microtime( true ); $font_content = $this->get_remote_content( $font_url ); if ( ! $font_content ) { @@ -107,6 +111,15 @@ public function write_font_css( string $font_url, string $provider ): bool { } $this->write_file( $local_path, $font_content ); + + $download_end = microtime( true ); + $download_time = $download_end - $download_start; + + $download_average += $download_time; + + ++$count_fonts; + + Logger::debug( "Font download duration -- $download_time", [ 'Host Fonts Locally' ] ); } $local_url = content_url( $this->get_fonts_relative_path( $font_provider_path, $font_path ) ); @@ -118,6 +131,8 @@ public function write_font_css( string $font_url, string $provider ): bool { // Add for test purpose. Logger::debug( "Font download and optimization duration in seconds -- $duration", [ 'Host Fonts Locally' ] ); + Logger::debug( "Number of fonts downloaded -- $count_fonts", [ 'Host Fonts Locally' ] ); + Logger::debug( "Average download time per font -- " . ( $count_fonts ? $download_average / $count_fonts : 0 ), [ 'Host Fonts Locally' ] ); return $this->write_file( $css_filepath, $local_css ); } From fff6c914edd8c2dabe84605d1a9f7fada7260fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 6 Dec 2024 11:23:22 -0500 Subject: [PATCH 3/4] fix styling --- inc/Engine/Media/Fonts/Filesystem.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Filesystem.php b/inc/Engine/Media/Fonts/Filesystem.php index 105212f981..5c3b64ea35 100644 --- a/inc/Engine/Media/Fonts/Filesystem.php +++ b/inc/Engine/Media/Fonts/Filesystem.php @@ -103,6 +103,7 @@ public function write_font_css( string $font_url, string $provider ): bool { if ( ! $this->filesystem->exists( $local_path ) ) { $download_start = microtime( true ); + $font_content = $this->get_remote_content( $font_url ); if ( ! $font_content ) { @@ -132,7 +133,7 @@ public function write_font_css( string $font_url, string $provider ): bool { // Add for test purpose. Logger::debug( "Font download and optimization duration in seconds -- $duration", [ 'Host Fonts Locally' ] ); Logger::debug( "Number of fonts downloaded -- $count_fonts", [ 'Host Fonts Locally' ] ); - Logger::debug( "Average download time per font -- " . ( $count_fonts ? $download_average / $count_fonts : 0 ), [ 'Host Fonts Locally' ] ); + Logger::debug( 'Average download time per font -- ' . ( $count_fonts ? $download_average / $count_fonts : 0 ), [ 'Host Fonts Locally' ] ); return $this->write_file( $css_filepath, $local_css ); } From 94361765427cf7747e2ee1cbbb16b286419bb54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 10 Dec 2024 09:35:06 -0500 Subject: [PATCH 4/4] update log messages --- inc/Engine/Media/Fonts/Filesystem.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/inc/Engine/Media/Fonts/Filesystem.php b/inc/Engine/Media/Fonts/Filesystem.php index 5c3b64ea35..e6559ddd66 100644 --- a/inc/Engine/Media/Fonts/Filesystem.php +++ b/inc/Engine/Media/Fonts/Filesystem.php @@ -56,16 +56,16 @@ public function exists( string $file ): bool { } /** - * Writes font css to path + * Writes CSS & fonts locally * - * @param string $font_url The font url to save locally. - * @param string $provider The url of the page. + * @param string $css_url The CSS url to save locally. + * @param string $provider The font provider. * * @return bool */ - public function write_font_css( string $font_url, string $provider ): bool { + public function write_font_css( string $css_url, string $provider ): bool { $font_provider_path = $this->get_font_provider_path( $provider ); - $css_filepath = $this->get_absolute_path( $font_provider_path, 'css/' . $this->hash_to_path( $this->hash_url( $font_url ) ) . '.css' ); + $css_filepath = $this->get_absolute_path( $font_provider_path, 'css/' . $this->hash_to_path( $this->hash_url( $css_url ) ) . '.css' ); $fonts_basepath = $this->get_absolute_path( $font_provider_path, 'fonts' ); if ( ! rocket_mkdir_p( dirname( $css_filepath ) ) ) { @@ -74,7 +74,7 @@ public function write_font_css( string $font_url, string $provider ): bool { $start_time = microtime( true ); - $css_content = $this->get_remote_content( html_entity_decode( $font_url ) ); + $css_content = $this->get_remote_content( html_entity_decode( $css_url ) ); if ( ! $css_content ) { return false; @@ -120,7 +120,7 @@ public function write_font_css( string $font_url, string $provider ): bool { ++$count_fonts; - Logger::debug( "Font download duration -- $download_time", [ 'Host Fonts Locally' ] ); + Logger::debug( "Font $font_url download duration -- $download_time", [ 'Host Fonts Locally' ] ); } $local_url = content_url( $this->get_fonts_relative_path( $font_provider_path, $font_path ) ); @@ -132,7 +132,7 @@ public function write_font_css( string $font_url, string $provider ): bool { // Add for test purpose. Logger::debug( "Font download and optimization duration in seconds -- $duration", [ 'Host Fonts Locally' ] ); - Logger::debug( "Number of fonts downloaded -- $count_fonts", [ 'Host Fonts Locally' ] ); + Logger::debug( "Number of fonts downloaded for $css_url -- $count_fonts", [ 'Host Fonts Locally' ] ); Logger::debug( 'Average download time per font -- ' . ( $count_fonts ? $download_average / $count_fonts : 0 ), [ 'Host Fonts Locally' ] ); return $this->write_file( $css_filepath, $local_css );