[wp-trac] [WordPress Trac] #59212: Call `add_user_meta()` when adding metadata to a new user

WordPress Trac noreply at wordpress.org
Sat Aug 26 13:29:00 UTC 2023


#59212: Call `add_user_meta()` when adding metadata to a new user
-------------------------+-----------------------------
 Reporter:  johnbillion  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Users        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  performance
-------------------------+-----------------------------
Description changed by johnbillion:

Old description:

> When a user is created via `wp_insert_user()`, several meta fields are
> added to the user (including nickname, first name, last name, and various
> preferences). These are all added using `update_user_meta()` instead of
> `add_user_meta()`. This means an unnecessary database query is performed
> for each meta field to first check whether a matching meta row exists.
>
> By switching to `add_user_meta()`, 11 database queries are saved by
> default when inserting a user.
>
> == Todo ==
>
> * Provide list of before/after queries when inserting a user
> * Provide steps for testing
> * Investigate the same for posts, comments, and terms in follow up
> tickets

New description:

 When a user is created via `wp_insert_user()`, several meta fields are
 added to the user (including nickname, first name, last name, and various
 preferences). These are all added using `update_user_meta()` instead of
 `add_user_meta()`. This means an unnecessary database query is performed
 for each meta field to first check whether a matching meta row exists.

 By switching to `add_user_meta()`, 11 database queries are saved by
 default when inserting a user.

 == Todo ==

 * Provide list of before/after queries when inserting a user
 * Confirm whether test coverage is sufficient
 * Provide steps for testing
 * Investigate the same for posts, comments, and terms in follow up tickets

--

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


More information about the wp-trac mailing list