Make WordPress Core

Changeset 55558


Ignore:
Timestamp:
03/17/2023 03:56:01 PM (16 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r55526 r55558  
    47154715        $authordata = get_userdata( $post->post_author );
    47164716
    4717         $currentday   = mysql2date( 'd.m.y', $post->post_date, false );
    4718         $currentmonth = mysql2date( 'm', $post->post_date, false );
    4719         $numpages     = 1;
    4720         $multipage    = 0;
    4721         $page         = $this->get( 'page' );
     4717        $currentday   = false;
     4718        $currentmonth = false;
     4719
     4720        $post_date = $post->post_date;
     4721        if ( ! empty( $post_date ) && '0000-00-00 00:00:00' !== $post_date ) {
     4722            // Avoid using mysql2date for performance reasons.
     4723            $currentmonth = substr( $post_date, 5, 2 );
     4724            $day          = substr( $post_date, 8, 2 );
     4725            $year         = substr( $post_date, 2, 2 );
     4726
     4727            $currentday = sprintf( '%s.%s.%s', $day, $currentmonth, $year );
     4728        }
     4729
     4730        $numpages  = 1;
     4731        $multipage = 0;
     4732        $page      = $this->get( 'page' );
    47224733        if ( ! $page ) {
    47234734            $page = 1;
Note: See TracChangeset for help on using the changeset viewer.