Current status: Solved. . Done
Serious Memory Issue using post object/relationship field with only 5000 posts
  • WP 3.4.1 ACF 3.2.5

    I just migrated data into wordpress from another content management system. Using ACF relationship field pointing to a post type with 5,000+ entries, the entry screen bonks entirely.

    This is the error I get:
    Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 89 bytes) in ../public/wp-includes/meta.php on line 571


    I've isolated this to the relationship field on that post type, and tried just using post object to no avail.

    I tried doubling the memory, but the message was the same - so appears to be something else.

    The server has lots of ram and generous settings (I'm on rackspace cloud servers). I'm not seeing anything in my error log, and there doesn't appear to be any conflicts and there are no other plugins using memory.

    I'm not using any sort of cacheing at this point, though I wouldn't think it would be necessary just to not bonk memory.

    This is a pretty big concern because 5,000 posts isn't a huge data set. Is there something I'm missing?



  • quick note - the front-end's not bonking under normal circumstances, just the add entry screen. Edited my post accordingly.
  • So I limited the posts in the relationship field (acf/core/fields/relationship.php line 79-83) to a couple thousand of the most recent to at least get things working. (on my server it slows around 4k, and bonks at about 4900).

    I'm surprised this issue hasn't come up before - didn't see any trace of this error in the forums. If anyone knows of a better solution, I'm still interested in a long-term fix.
  • Me again. I did some tests limiting the numberposts and that won't work because if the the related post does not show on the left hand side of the relationship field (i.e. it's not longer in the most recent X articles), then it disappears from the right hand side.
  • Hi budparr,

    Yes, this is a known problem with the relationship field and also with any of the page link and post object fields. They are only intended to be used with small scale websites.

    You may need to create you own field where you look-up the posts via an ajax name search. This would reduce the number of posts queried and would allow your server to run.

    There is documentation for creating your own field but that's all the help I can offer at the moment.

    In the future I will re-code the relationship field to limit the entries with a more button and use ajax to search through the posts.

    Hope that helps
  • Thanks - I was thinking the same thing. If I manage to do it, I'll be sure to share. Otherwise, of course, all the ACF fields are nicely polished and work really well.
  • I was have a similar issue Memory Issues but only having > 75 and < 125 posts in my CPT.
    I added this to the array in relationship.php

    'update_post_meta_cache' => false,

    I found the info in the WP Codex:
    http://codex.wordpress.org/Class_Reference/WP_Query
    "Parameters relating to caching"

    It seems to be working on the problem CPT and on others that have only a few posts used for other relationship custom fields.

    acf/core/fields/relationship.php
    Line 60 - 76 now looks like this:
    function acf_get_relationship_results()
    {
    // vars
    $options = array(
    'post_type' => '',
    'taxonomy' => 'all',
    'posts_per_page' => 10,
    'paged' => 0,
    'orderby' => 'title',
    'order' => 'ASC',
    'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
    'suppress_filters' => false,
    's' => '',
    'lang' => false,
    'update_post_meta_cache' => false ,

    );

    If you think this is no good, let me know. I will run it and see what happens.
  • Hi @mydarndest,

    This is very interesting. I don't see the harm in adding this in so I might do.

    Cheers
    Elliot