WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#15854 closed defect (bug) (fixed)

get_users/WP_User_Query is not scalable

Reported by: duck_ Owned by:
Milestone: 3.1 Priority: highest omg bbq
Severity: blocker Version: 3.1
Component: General Keywords: has-patch commit
Focuses: Cc:
PR Number:

Description

Related: #15786, #14572

Use of get_users (and by extension WP_User_Query) is not scalable for sites with a large number of users. Fatal errors occur when caching all the resulting users to memory.

Example usage which causes fatal errors in 3.1 (no fatal error in 3.0.3 for a site with even more users):


And probably others, grep for get_users.

Patches for first to examples attached, but I can't help but feel this is just papering over the issue.

Attachments (3)

class-wp-xmlrpc-server.php.diff (776 bytes) - added by duck_ 9 years ago.
wp-admin.users.php.diff (1.3 KB) - added by duck_ 9 years ago.
15854.diff (3.4 KB) - added by scribu 9 years ago.
Deprecated get_users_of_blog()

Download all attachments as: .zip

Change History (19)

#1 @scribu
9 years ago

(In [17010]) Use wp_dropdown_users() in the delete confirmation screen. Props duck_. See #15854

#2 @scribu
9 years ago

(In [17011]) Get only required fields in wp_getAuthors(). Props duck_. See #15854

#3 @scribu
9 years ago

I guess we should add a 'cache_results' parameter to WP_User_Query and set it to false by default.

#4 @scribu
9 years ago

(In [17012]) Get only required fields in populate_network(). See #15854

#5 @scribu
9 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [17013]) Make WP_User_Query return regular objects by default. Fixes #15854

#6 @westi
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

This change breaks backwards compat for get_users_of_blog

In 3.0 this joined on the usermeta table and returned and array of stdclass with the caps as a properties too.

It doesn't anymore after this last set of changes.

#7 @scribu
9 years ago

  • Keywords has-patch added

In 3.0 this joined on the usermeta table and returned and array of stdclass with the caps as a properties too.

More precisely, it had a 'meta_value' property, which contained the capabilities:

http://core.trac.wordpress.org/browser/tags/3.0.3/wp-includes/user.php#L328

#8 @scribu
9 years ago

I propose we revert get_users_of_blog() to it's 3.0 state and deprecate it.

#9 @scribu
9 years ago

  • Keywords has-patch removed

@scribu
9 years ago

Deprecated get_users_of_blog()

#10 @scribu
9 years ago

  • Keywords has-patch added

#11 @westi
9 years ago

deprecating the function and restoring the old direct SQL is lame.

Is there no way to wrap get_users and still return the old data structure?

#12 @scribu
9 years ago

deprecating the function and restoring the old direct SQL is lame.

To that I will reply that get_users_of_blog() is lame. :)

Is there no way to wrap get_users and still return the old data structure?

Only if we loop through each result, serialize back the 'capabilities' property and add it as 'meta_value'.

#13 @ryan
9 years ago

Per IRC discussion, going with 15854.diff.

#14 @scribu
9 years ago

  • Keywords commit added

#15 @ryan
9 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [17084]) Revert get_users_of_blog() to 3.0 behavior and deprecate. Use get_users() in core. Props scribu. fixes #15854

#16 @nacin
9 years ago

Glad things get tested before commit. [17010] was borked and wasn't caught until now. #16361

Note: See TracTickets for help on using tickets.