Custom Fields
Support MB Relationships Relationship field performance

  • Creator
  • #15874
    Resolved Content Pilot

    Hi Anh,

    We have been using the MB Relationships extension on the platform we have built and everything was going well, but on our last site with more data than I have handled so far we have encountered performance problems in the loading of the relationship fields.
    What I have seen and please correct me if I am wrong, is that the selects on the relationship fields are builded with Post fields and in each of them query all posts of that post type and this is killing the database.

    My thought is to set a pagination here and then get a lazy loading going so that when a person opens a select field and scrolls to the bottom of the list or types in a name into the search field, a query is then made to populate the next 50 or 100 posts or the proper search result. This will probably happen via Ajax.

    Some of our posts have 700 relationships and more than 4,000 possible options within individual relationship fields.

    Do you think my analysis is correct? And do you think that implement paging and lazy loading to solve it is a good approach?

    This is very important for the site I am building, and time sensitive because the admin remains unusable until it is fixed. Thank you for your time.

Viewing 8 replies - 11 through 18 (of 18 total)
  • Author
  • #16067
    Anh Tran

    Update: the ajax + pagination is enabled by default and works for terms and users. Please use the latest version on ajax-post branch on Github:

    Please try it before I release a new version.

    Content Pilot

    Thanks so much for the solution Anh, we have noticed that the time to editing the relationship fields is greatly improved. The customization of parameters also worked well. However, we still find two more moments where the load becomes really heavy in post with many relationships.

    One of those moments happens when the user open a closed relationship field. We understand that there is not much to do, since all relationships are loaded only once.
    The other moment is in the initial charge. We are not sure that this happens there, but it’s possible not to query any relationships for the relationship fields closed? In this way, a lazy load could be added that loads only the relationship field requested by the user.

    Please correct me if I am wrong or if you find something else that can improve the initial load of the editor that is still very heavy.

    Anh Tran

    Glad you like it.

    Do you want to remove an ajax query when users open a closed relationships field? I understand “closed relationship field” is a field that users already chose items for the relationship, right?

    Well, what if users want to change a selected item to something else? We still need to make ajax query to fetch other items for users to change.

    FYI, if a field already has some selected items, only once query is made when page loads (not via ajax). It makes sure the selected items is visible in the dropdown.

    If field has no selected items, no queries are created when page loads. Queries are created only via ajax.

    Content Pilot

    My thought is to remove the queries that are made when the page loads, only for the relationship fields that are closed closed => true

    So we use the ajax query to fetch the items when the user open the field.
    If the field is set open, those queries cannot be omitted in the page load since the selected items must be displayed from the start.

    Although when the page load the queries are done only once, having several relationship fields and many elements selected in each one, all queries are made even if the user does not need to edit the fields.

    This is just my guess, you can tell me if it’s feasible. Thanks again.

    Anh Tran

    I got it. Thanks for the clarification.

    I’m afraid there’s no way to detect a field is closed or open, especially in different context (classic or block editor).

    At the moment, the queries when page loads are minimal as they query only selected items. I don’t think that’s a performance bottle neck.

    Content Pilot

    I understand Anh, I’ll return if I have any idea how to improve it further.

    At the moment we will try to reduce with the client the amount of relationships for the posts that still load very slow (some load more than 100 MB)

    I also noticed that yesterday you integrated it into the new versions of meta-box and mb-relationships.
    Thanks for all the help.


    Hello, can you update the link?
    I got 404 for this:

    also when you will merge all this to master and realese the new version including all this improvements?

    Anh Tran

    Hi, it’s merged into the master branch, and is available in the Meta Box 5.2. Please just update and you’ll have it.

Viewing 8 replies - 11 through 18 (of 18 total)
  • You must be logged in to reply to this topic.


Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.

grid gear info copy caret-up caret-down trash