[wp-trac] [WordPress Trac] #59269: Add support for adding metadata in bulk

WordPress Trac noreply at wordpress.org
Fri Sep 1 22:39:01 UTC 2023


#59269: Add support for adding metadata in bulk
-------------------------+-----------------------------
 Reporter:  johnbillion  |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Database     |    Version:
 Severity:  normal       |   Keywords:
  Focuses:  performance  |
-------------------------+-----------------------------
 Related: #34848

 This ticket aims to introduce functions for bulk inserting metadata in a
 manner that's more performant than calling the `add_*_meta()` functions
 multiple times per object. This is particularly beneficial during large
 imports or data generation where `add_*_meta()` is called many times for a
 large number of users, posts, comments, or terms.

 This can be achieved by inserting all the metadata for the object in one
 INSERT query and only deleting the object's meta cache once. The existing
 filters and actions that are triggered when calling the `add_*_meta()`
 functions individually should still all be fired as expected, once for
 each meta key.

 The performance benefit should grow as the number of rows to insert
 increases, because both the number of database queries and the number of
 cache deletions for the object should remain constant (`O(1)`) rather than
 increasing correspondingly to the number of rows (`O(n)`).

 That said, there does appear to be a sweet spot after which the
 performance of one large INSERT query starts to degrade, although
 according to the PHPBench tests I've added it still remains overall more
 performant than multiple queries. Some more testing is needed across
 different payload sizes and database versions.

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


More information about the wp-trac mailing list