[wp-hackers] get_users() exhausts memory with 'all_with_meta' argument
Mike Walsh
mpwalsh8 at gmail.com
Fri Jan 3 20:33:31 UTC 2014
It turns out the 'all_with_meta' wasn't necessary at all. In the pre-3.x
days before the advent of the magic methods for the get_users() function
[see this: http://scribu.net/wordpress/the-magic-of-wp_user.html] the
'all_with_meta' was used to retrieve the first and last names for each user
which is stored in the meta table. Now that the meta data exists through
the 'magic' of get_users(), I no longer need 'all_with_meta' so I simply
eliminated the argument. Now the memory usage for this site of 13k users
never goes above 46M-47M.
<!-- email-users.php::1084 Query #0 Memory Usage: 34.5M --><!--
email-users.php::1084 Query #1 Memory Usage: 34.75M --><!--
email-users.php::1084 Query #2 Memory Usage: 35.25M --><!--
email-users.php::1084 Query #3 Memory Usage: 35.75M --><!--
email-users.php::1084 Query #4 Memory Usage: 36.5M --><!--
email-users.php::1084 Query #5 Memory Usage: 37M --><!--
email-users.php::1084 Query #6 Memory Usage: 37.5M --><!--
email-users.php::1084 Query #7 Memory Usage: 37.75M --><!--
email-users.php::1084 Query #8 Memory Usage: 38.5M --><!--
email-users.php::1084 Query #9 Memory Usage: 39M --><!--
email-users.php::1084 Query #10 Memory Usage: 39.5M --><!--
email-users.php::1084 Query #11 Memory Usage: 39.75M --><!--
email-users.php::1084 Query #12 Memory Usage: 40.25M --><!--
email-users.php::1084 Query #13 Memory Usage: 40.75M --><!--
email-users.php::1084 Query #14 Memory Usage: 41.25M --><!--
email-users.php::1084 Query #15 Memory Usage: 41.5M --><!--
email-users.php::1084 Query #16 Memory Usage: 42.5M --><!--
email-users.php::1084 Query #17 Memory Usage: 43M --><!--
email-users.php::1084 Query #18 Memory Usage: 43.5M --><!--
email-users.php::1084 Query #19 Memory Usage: 44M --><!--
email-users.php::1084 Query #20 Memory Usage: 44.5M --><!--
email-users.php::1084 Query #21 Memory Usage: 44.5M --><!--
email-users.php::1084 Query #22 Memory Usage: 45.25M --><!--
email-users.php::1084 Query #23 Memory Usage: 45.75M --><!--
email-users.php::1084 Query #24 Memory Usage: 46M --><!--
email-users.php::1084 Query #25 Memory Usage: 46.5M --><!--
email-users.php::1084 Query #26 Memory Usage: 47M -->
I am not sure I need to break the query up into chunks of 500 any more
although I supose it doesn't hurt anything if I do. I could also add
some sort of a fail safe that if memory approaches the max limit WP
defines, I could terminate the loop.
As always, thanks for the help on wp-hackers.
Mike
On Fri, Jan 3, 2014 at 2:33 PM, Otto <otto at ottodestruct.com> wrote:
> On Fri, Jan 3, 2014 at 1:29 PM, Mike Walsh <mpwalsh8 at gmail.com> wrote:
> > To answer some of questions - the opt-in aspect is exactly what is stored
> > as meta data. I took over this plugin a while back and this query model
> > has been part of it long before I started working on it. Basically it
> does
> > a query for all users which have meta data and processes that. The Codex
> > indicates the meta query has been available since 3.5.0 and this plugin
> > dates back to the 2.x days.
>
> Cool. So instead of doing get_users(array('fields' =>
> 'all_with_meta')), change it to:
>
> get_users(array(
> 'meta_key' => 'your-opt-in-key',
> 'meta_value' => 'your-opt-in-value',
> ) )
>
> And you should be good to go, most likely. This will only get the
> users opted in and it won't try to cache all the meta data for all the
> users at once.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
Mike Walsh - mpwalsh8 at gmail.com
More information about the wp-hackers
mailing list