Ouch. Sorry to hear that these specific queries are resulting in a slower experience. That certainly wasn’t the plan on our end. Are you able to provide an exact spec so that we can duplicate your approach? That will go a long way towards allowing us to figure out what’s happening, and improve/fix it.
John,
Thanks. I’m sure caching that data speeds things up in normal use, however I do regularly need to export all the extended profile fields, and it doesn’t make sense to try and cache that.
What exactly do you need to know? I’ve got 13302 users, with roughly 115 extended profile fields (many of which tend to be blank for a given user). My little test script is below, although what I actually use is the “Export User Data” plugin.
<?php
/*
Template Name: test template
*/
?>
<h2>TEST of BP_XProfile_ProfileData::get_all_for_user</h2>
<?php
global $bp;
$start_time=microtime(true);
$memory_use = memory_get_usage(true) / 1024 / 1024;
echo "<br/>Start Memory Use = $memory_use MB";
for ($userid = 1; $userid <= 5000; $userid++) {
BP_XProfile_ProfileData::get_all_for_user($userid);
}
$times_run = $userid -1;
$finish_time = microtime(true);
$elapsed_time = $finish_time - $start_time;
$avg_time = $elapsed_time / $times_run;
echo "<br/>Ran get_all_for_user for $times_run users";
echo "<br/>Elapsed time = $elapsed_time seconds";
echo "<br/>Avg time = $avg_time seconds";
$memory_use = memory_get_usage(true) / 1024 / 1024;
echo "<br/>End Memory Use = $memory_use MB";
echo "</p>";
?>
@cwjordan – Thanks for the benchmarks. Are you using an object cache? If not, since you’re fetching profile data in a loop like this, I would temporarily disable object caching manually.
See:
http://kovshenin.com/2012/disable-object-cache-additioninvalidation-in-wordpress/
Let me know if that helps.
@r-a-y Thanks! You are right, I’m not using an object cache. That function isn’t in the WordPress codex, so I missed it. It looks very much like what I wanted, except that I’m a bit worried, because if I follow the Buddypress logic correctly, Buddypress gets the data, puts it into the cache, and then reads it from the cache to give it to the caller. Hope I misread that or something. Anyway I’ll give it a try when I get a chance and let you know. Otherwise I have a workaround, just pull the old version of the function into the plugin I’m using and use that. Just a workaround though.