Custom Fields
Re-Envisioned
Support MB Relationships Relationship field performance

This topic contains 16 replies, has 2 voices, and was last updated by  Content Pilot 4 days, 20 hours ago.

  • Creator
    Topic
  • #15874
    Resolved
    Content Pilot
    Participant

    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 6 replies - 11 through 16 (of 16 total)
  • Author
    Replies
  • #16067

    Anh Tran
    Keymaster

    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:

    https://github.com/wpmetabox/meta-box/tree/ajax-post

    Please try it before I release a new version.

    #16080

    Content Pilot
    Participant

    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.

    #16084

    Anh Tran
    Keymaster

    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.

    #16100

    Content Pilot
    Participant

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

    https://take.ms/BNYsX

    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.

    #16105

    Anh Tran
    Keymaster

    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.

    #16188

    Content Pilot
    Participant

    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.

Viewing 6 replies - 11 through 16 (of 16 total)

You must be logged in to reply to this topic.