From 0e55b6ab849695606ff6dffbf030e6d478e94c0d Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Fri, 17 Mar 2023 15:58:23 +0000 Subject: [PATCH] Date / Time: Remove usage of mysql2date in generate_postdata method. Remove usage of `mysql2date` in `generate_postdata`. `mysql2date` has a performance overhead, as it creates a `DateTimeZone` object each time it is called. Use a simple sub string function to generate the values needed for the `currentmonth` and `currentday` global variables. Props spacedmonkey, Rarst, SergeyBiryukov, flixos90. Fixes #57683. Built from https://develop.svn.wordpress.org/trunk@55558 git-svn-id: http://core.svn.wordpress.org/trunk@55070 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-query.php | 21 ++++++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index d5d10e9714..94512908bf 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -4714,11 +4714,22 @@ class WP_Query { $authordata = get_userdata( $post->post_author ); - $currentday = mysql2date( 'd.m.y', $post->post_date, false ); - $currentmonth = mysql2date( 'm', $post->post_date, false ); - $numpages = 1; - $multipage = 0; - $page = $this->get( 'page' ); + $currentday = false; + $currentmonth = false; + + $post_date = $post->post_date; + if ( ! empty( $post_date ) && '0000-00-00 00:00:00' !== $post_date ) { + // Avoid using mysql2date for performance reasons. + $currentmonth = substr( $post_date, 5, 2 ); + $day = substr( $post_date, 8, 2 ); + $year = substr( $post_date, 2, 2 ); + + $currentday = sprintf( '%s.%s.%s', $day, $currentmonth, $year ); + } + + $numpages = 1; + $multipage = 0; + $page = $this->get( 'page' ); if ( ! $page ) { $page = 1; } diff --git a/wp-includes/version.php b/wp-includes/version.php index a0c3b24bc8..a2c5f31937 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55557'; +$wp_version = '6.3-alpha-55558'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.