Opened 15 months ago
Last modified 15 months ago
#59269 new enhancement
Add support for adding metadata in bulk
Reported by: | johnbillion | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Database | Keywords: | has-patch has-unit-tests |
Focuses: | performance | Cc: |
Description
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.
Change History (3)
This ticket was mentioned in PR #5128 on WordPress/wordpress-develop by @johnbillion.
15 months ago
#1
- Keywords has-patch has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/59269