Skip to:
Content
Pages
Categories
Search
Top
Bottom

request for way to disable caching of xprofile data for get_all_for_user


  • cwjordan
    Participant

    @cwjordan

    To export my extended profile data I run BP_Xprofile_ProfileData::get_all_for_user for each user. Since version 2.0 of Buddypress came out I notice this has gotten much slower. I assume it’s because this data gets cached now. While I see that caching is great for every day use, it would be nice to disable it for specific queries. Could you please add an optional parameter to get_all_for_user to tell it not to cache the data?

    I wrote a quick script to do some timings, and on my old development computer if I run get_all_for_user for 5000 users with the old version 1.9.2 it takes 1.7 seconds, while with version 2.0.3 it takes 148.7 seconds, and uses a lot more memory as well (507 MB with the new version versus 41 MB with the old).

Viewing 4 replies - 1 through 4 (of 4 total)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    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.


    cwjordan
    Participant

    @cwjordan

    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>";
    ?>

    r-a-y
    Keymaster

    @r-a-y

    @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.


    cwjordan
    Participant

    @cwjordan

    @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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘request for way to disable caching of xprofile data for get_all_for_user’ is closed to new replies.
Skip to toolbar