[wp-trac] [WordPress Trac] #57901: Only process queue in lazy loading meta api, if request id is in queue.

WordPress Trac noreply at wordpress.org
Mon Mar 20 22:44:56 UTC 2023


#57901: Only process queue in lazy loading meta api, if request id is in queue.
--------------------------------+------------------------------
 Reporter:  spacedmonkey        |       Owner:  (none)
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:  4.5
 Severity:  normal              |  Resolution:
 Keywords:  has-patch           |     Focuses:  performance
--------------------------------+------------------------------

Comment (by peterwilsoncc):

 Gotcha, in that case I think it better to dynamically add the ID of the
 current object the the lazy loading method:

 {{{#!php
 <?php
 public function lazyload_term_meta( $check, $object_id ) {
         if ( ! empty( $this->pending_objects['term'] ) ) {
                 $object_ids = array_keys( $this->pending_objects['term']
 );
                 if ( ! in_array( $object_id, $object_ids, true ) ) {
                         $object_ids[] = $object_id;
                 }
                 update_termmeta_cache( $object_ids );

                 // No need to run again for this set of terms.
                 $this->reset_queue( 'term' );
         }

         return $check;
 }
 }}}

 To my mind, queuing meta data for lazy loading is to say: only query the
 meta data table if there is an indication a theme or plugin is using the
 meta data for that object type.

 Calling `get_type_meta()` for any object ID, whether or not it's queued,
 is that indication.

 > Another solution to this problem, is dynamically adding the missing id
 to the queue, but again, this may result in loading data that is not
 needed.

 I acknowledge that is a risk, but it's always been there. Using
 [https://querymonitor.com/blog/2018/07/profiling-and-logging/ QM's
 profiling] feature didn't show a great deal of extra memory usage in my
 quick testing.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57901#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list