Media Library overloads the server

We have a photograph that has multiple pictures in the same gallery that we made using The Grid.

When anybody clicks “Add images” in the “Source” tab of a grid, the media library opens up with selectable images (to add to The Grid) and crashes the server by taking 100% of the server resources.

We confirmed with The Grid developers that the plugin wasn’t the cause, the native WPMU media library when selecting pictures doesn’t seem optimized for 100 pictures at the same time even though it’s loaded through AJAX.

Would it be possible to get support about this to help us understand why it would do that?

It’s a WordPress Multisite, so our guess is that MySQL queries take into account tables they shouldn’t touch (other sites’:wink:.

If you can help us, we can provide full access to the installation. We do not have a staging area yet, sadly. We don’t mind if you reproduce the problem and crash the server, we just want it fixed / optimized. :slight_smile:

  • Adam Czajczyk
    • Support Gorilla

    Hi Magik Web

    I hope you’re well today and thank you for your question!

    A standard Media Library “selection window” shouldn’t cause that. I’m referring to the regular “Add media” button in the back-end that shows up when you, for example, want to add an image to the post. By default it’s loading only a bunch of images and then loads more “on the fly” while you scroll – as you rightfully notice already, via ajax.

    I got no “hickups” on my test site with over 2,5k of images and have seen sites with tens of thousands of them. But there’s always a chance that something “unexpected” is happening – that might be caused by some other plugin or somehow related to the server, it’s difficult to say right away.

    I would like to take a look at that first. When the site gets overloaded – is it enough to wait a moment for it to get back or do you need to take some additional action (like, for example, restart server)?

    Would you mind opening a support access to the site so I could take a look? To do this, please go to the “WPMU DEV -> Support” page in your site’s back-end and click on “Grant support access” button there.

    Let me know, please, once it’s enabled and it would also be great if you could give me a bit more detailed guide on how can I replicate the issue on your site (where to go on site, what to click and so on).

    Best regards,

    Adam

  • Vince
    • Flash Drive

    Hello Adam,

    Thank you for your reply! I have granted support access as suggested.

    How to reproduce the problem:

    1. In the left-side menu, click “The Grid -> The Grid”

    2. Click “Edit” on the “photos” gallery (ID 302)

    3. Click the “Source” tab

    4. Go down under the numerous images to see the small button “Add images”

    (This image didn’t upload with the post, click here to see it)

    The media library that shows has an AJAX loading that clogs up the whole server.

    The websites come back after 30s to 90s, most likely from timeouts.

    If there is anything you need (technical or not), please let us know. Your help is greatly appreciated!

    PS: We’re impressed at how wpmudev integrates with support.

  • Adam Czajczyk
    • Support Gorilla

    Hi Magik Web

    Thanks for explanation and enabling access. One thing I noticed so far is that the site in question is using quite big images on front-end (dynamically rescaled) so that might be somehow related.

    However, I wasn’t able to check that particular site yet. The support access is active and it gives me a super-admin level access but sub-sites are using WP core domain mapping and that means that when I try to access aforementioned sub-site, it asks me to login with login and password – which I’m not able to do.

    To step over it, would you please create a real (additional one, you’ll remove it after we’re done with this) account for me? You can use any e-mail and username, just make sure that the account is given a super-admin role.

    Once it’s created, please go to the “Network Admin -> WPMU DEV -> Support” page and put it into the text box below “Access active for…” green button, then save it and let me know here than it’s done (just don’t post credentials here).

    This way, once you let me know I’ll access the site again and I’ll be able to get account login credentials from there and use them to login to that sub-site and check it.

    Best regards,

    Adam

  • Predrag Dubajic
    • Support

    Hi Magik Web,

    Thanks for providing us access to the subsite, I check the media library in The Gird and can indeed see the issue there.

    It seems that the library is firing up over 100 ajax requests at the same time and that hogs server resources.

    I also checked media library when trying to add an image in regular page and that actually worked fine.

    So it seems it’s something specific to The Grid that’s causing this issue, it’s most likely either a conflict with some other product on your site or there’s some bug in the plugin itself.

    I would suggest checking for conflicts first by disabling all your other plugins and switching to default WP theme and see if the issue is gone.

    If it’s still there then you should discuss this further with The Grid developers so they can investigate it further and see what’s causing that overwhelming number of AJAX requests.

    Please make sure that you have full backup of your site before doing a conflict test, just to stay on the safe side.

    Best regards,

    Predrag

  • Vince
    • Flash Drive

    Thank you Predrag for the follow-up, it's very helpful.

    This is another piece of information that we didn't have that will help us solve this issue.

    We already contacted The Grid and disabled the media library taxonomy they use to eliminate the possibility of their plugin being the culprit. (See attached file, there is no private information)

    Nonetheless, we need a staging environment and now that we're joining WPMU Dev, I think the plugin "Cloner" (if I'm not mistaken) could help us out with that.

    We'll try cloning the site on a different URL, disable a few plugins and test it out. We only have one question about the "Cloner" plugin; can we disable a network-enabled plugin without disturbing the live sites?

    Thank you for your patience!

  • Adam Czajczyk
    • Support Gorilla

    Hi Magik Web

    The “Cloner” plugin would let you make a copy of selected sub-site of a Multisite so it should be of help here, though please note: I’m not sure about behavior on in case of sub-site set on domains mapped using native WP mapping. It should work fine but you’ll need to give it a try first.

    The good news is, it doesn’t make any changes whatsoever to a source site so it would be safe to try.

    As for network-enabled plugins. If a plugin is network enabled it can’t be disabled for just one site, it’s either entire network or nothing and disabling for entire network may or may not cause issues – but that depends mostly on the plugin: what it does and how it works.

    Best regards,

    Adam

  • Vince
    • Flash Drive

    Hello Adam,

    Small follow-up; After changing the theme to Twenty Seventeen and disabling all plugins I could disable, the problem still occurs. It seems like for every selected image, there is an AJAX call (get attachment) and they are all triggered upon opening the media library.

    The test site you mentioned, does it have a lot of selected images in a grid (or another plugin)?

    In the meantime, we'll search furthermore to validate if it's a native behavior or if The Grid is the one doing the calls upon clicking the button.

  • Adam Czajczyk
    • Support Gorilla

    Hi Magik Web

    The test site you mentioned, does it have a lot of selected images in a grid (or another plugin)?

    Do you mean the test site that I mentioned in my first response (“I got no “hickups” on my test site with over 2,5k of images”:wink:? If yes, then no – I didn’t test that this way and I didn’t actually even test it with The Grid. My point was that in general WordPress itself should not have trouble handling that big Media Library :slight_smile:

    As for The Grid an your last update. That number of ajax calls for selected images would suggest that the plugin is, for some reason, checking (maybe pre-fetching?) some data for each of these images when they are selected. I’m not quit sure why, tho.

    I just took a look at the clean setup, trying to insert image to the post and then also trying to insert a gallery (so selecting multiple images) and there’s no ajax calls during selection process. Media LIbrary (actually the “Add media” popup part) is making admin-ajax calls but basically upon init and then when you scroll the image list (which, I believe, is done to fetch not-yet-visible images). Selecting/deselecting images alone doesn’t trigger ajax. If that happens with The Gird, even if other plugins are disabled, that would mean that The Grid is doing that.

    That said, I did an experiment.

    First, I created a simple grid and put it on a clean page. Then I used “gallery” tab to add images to it (I think about 30-40) and saved it and published the post. Then used “Add images” button to add more images. Immediately after I clicked that button I got a long set of admin-ajax calls, just like you.

    So then, instead of using The Grid, I just created a native WP gallery in another post, published the post and went back to edit it. Once I clicked on “Edit” button on that gallery, I got pretty much the same popup with Media Gallery to select additional images from. But… no admin-ajax calls at all.

    I think this is related to The Grid then. These calls aren’t actually fetching much of an info from what I can see and I’m not sure why they are there but they doesn’t seem to happen without The Grid.

    Best regards,

    Adam

  • Vince
    • Flash Drive

    Hiyo Adam,

    Thank you very much for your help and we’re seriously impressed that you went the extra mile to test it out for us. Good support is rare and is worth gold. It didn’t fix the issue, but we learned a bunch of stuff.

    The Grid’s support team insists that it’s a native WordPress behavior and that it has nothing to do with the plugin. We respect that and will migrate to a different gallery plugin to solve our client’s needs.

    We’ll start reading the community’s posts to avoid duplicate questions and join in.

    Kind regards,

    Vince

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.