[wp-trac] [WordPress Trac] #57683: Improve performance of mysql2date

WordPress Trac noreply at wordpress.org
Thu Feb 9 18:38:13 UTC 2023


#57683: Improve performance of mysql2date
--------------------------+----------------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  Date/Time     |    Version:  0.71
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+----------------------------
 The `mysql2date` function is used in WP_Query. In the following lines.

 {{{#!php
 public function generate_postdata( $post ) {
   ...
   $currentday   = mysql2date( 'd.m.y', $post->post_date, false );
   $currentmonth = mysql2date( 'm', $post->post_date, false );

 }}}

 However, this results in a call to `wp_timezone`, which creates a new
 `DateTimeZone` and calls to `wp_timezone_string` which does two calls to
 `get_option`.

 As `mysql2date` is called twice every time a post is setup, this can
 result in hundreds of calls to `get_option` / `wp_timezone`. This is very
 wasteful, as even simple calls to get_option have overhead.

 As it is very unlikely for the timezone will change in a single page
 request, the result of the timezone should be cached somehow to stop
 reprocessing.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57683>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list