[wp-trac] [WordPress Trac] #44921: User nicename discovery is slow to return

WordPress Trac noreply at wordpress.org
Sat Sep 8 12:12:26 UTC 2018


#44921: User nicename discovery is slow to return
--------------------------+-----------------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Users         |    Version:  2.0
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 In the function `wp_insert_user` it checks to is if the user nicename is
 in use by another user before saving. This is because, a nicename should
 is required to be unique. Unlike usernames, however, that rejects already
 in use usernames, if first checks to see if the nicename is in uses, then
 runs a while loop to try and find the next available nicename with a
 suffix. So nicename jonny becomes jonny_2 if jonny is already in use.

 The behaviour is fine, however it uses a while loop to find the next
 available nicename, which can result in an extremely high number of
 queries. Take the following use case.

 You have a script that generates 10000 test users for a site. The call to
 wp_insert_user, passed `'user_nicename' => 'test_user'`. Within the
 function call, it will run the while loop and find next available
 nicename. By the 9999th call, it would have to loop around 9999 to find
 the next slot, making the return of wp_insert_user extremely slow.

 For testing scripts and sites with lots of registered users, this could
 make `wp_insert_user` almost unusable.

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


More information about the wp-trac mailing list