Problem/Motivation
The JsTree which is found on the media browser tab takes a very long time to load images. I am currently trying out the module and by default all the media files (1000+) are in the default folder (root). On my dev environment it too 3-5 minutes before all the images were loaded. On my local environment it took forever.
Contrast that to the media library which is almost instant.
From the console it shows that there is a POST Request to admin/media_directories/directory/tree/content?_wrapper_format=drupal_ajax which takes forever (hangs), could be the cause.
Steps to reproduce
1. Install module
2. Enable module and it's sub modules
3. Navigate to admin/config/media/media_directories add the vocabulary to use as directories, then save
4. Navigate to admin/content/browser and wait.
Workaround
By installing views infinite scroll, this issue is tamable, see https://www.drupal.org/project/media_directories/issues/3185648#comment-... (Thank's to sun-fire)
Proposed resolution
Not sure
Comments
Comment #2
bajah1701 commentedComment #3
ytsurkSeems like you found a bottleneck. I'll investigate.
We may need to introduce pagination, like media library ..
Could you please try also with version 2.0.1 (although I guess it's the same)?
Does this happen every time, or only the first time (where the image derivates/styles are generated)?
Comment #4
ytsurkLocally, with 1000 media entities I wait 44s for
- if the cache is warmed-up, it takes about 25s, and with 200 media entites for 5s. Not soo tragic ;)
Anyway, seems like there might be improvement possible, fe. tree caching ..
What's your local setup? How does it perform on a server/non-dev-environment?
Do you have any other modules installed, that hook the taxonomy or media load process?
Comment #5
EricRondo commentedHi,
Same problem for me, i have hundreds of images and the media browser is very slow (~20s to load, and still slow after).
It would be very useful to introduce pagination indeed !
Thanks a lot
Comment #6
ytsurkUnsure about pagination .. we have directories/folders.
Also jsTree has no active pagination support ..
Comment #7
ytsurkComment #8
EricRondo commentedWell even after reorganizing our medias, it is still very slow, because each folder has hundreds of images ;-)
Comment #9
sun-fire commentedHi!
I faced the same issue using the latest version of the Media directories module. When I did some debugging, I found that most slowdowns were related to the part of code that displays the items in the selected folder.
So, as I see in code, technically the files are displaying using Views item called "media_directories_base", especially it's related to building the image presets and bulk operation form items.
So, in my case, I resolved the issue by installing the module "Views infinite scroll" and adding a pager with the mode "Infinite scroll" using 45 images per page.
So, technically, after these changes, if the folder contains more than 45 media items - only the first 45 will be displayed, and the "Load more" button will be displayed in the bottom of the files list. So, a user could click on "Load more", and load next 45 items.
In my case, the performance issue was resolved, and this solution could be used but needs to be reviewed by the community as well and if it works properly and is suitable for the people - probably this dependency could be added to the codebase (I can provide a patch as well).
Comment #10
sun-fire commentedComment #11
ytsurkFunky solution to the problem sun-fire :D
Comment #12
ytsurkComment #13
ytsurkI now suggest the installation of another module as workaround.
Let me think of taking this as a recommendation to the project page.
So this is now a documentation task ;)
Comment #14
ytsurkI said task ;)
Comment #15
klidifia commentedConfirm the views infinite scroll pager usage on the view works well, thanks sun-fire.
Comment #16
redeight commentedI've had this issue cause an error on two of my sites with thousands of media items and the error message is so unhelpful (http 500 error with ajax) it took me hours to realize what was happening the first time. I'd suggest adding pagination to the default view as that fixes it, though slightly less elegantly than the suggested workaround. But at least it doesn't require installation of another module or a dependency on that module from this one.
Comment #17
rang501 commentedThis issue seems to be coming up again and again. I have it on one site as well. Views is just so slow when trying to render a lot of entities at once. It needs some POC first to see how different it is.
So we should work on it.
I'm proposing two options:
1. Integrate views_infinite_scroll (either as a dependency or switch if the module is installed on the site)
2. Add a second listing type based on the entity query, which is way faster than Views (in both loading entities and rendering)
Comment #18
ytsurkThank you all for your inputs, and yes, we definitely should address this now.
Demand seems here, and we should have larger installations in mind.
Why not just introduce pagination, using the current admin themes pagination at the end of the scroll-able media area ?
I don't like the idea of having another dependency (infinite scroll, which I like a lot) - especially for something we can do our self with minimal effort.
Thinking more about that, an endless scroll would be a great fit IMO.
Why not implement our own views pagination, just having a load more button maybe having one or two settings like pagesize (bonus:auto-scroll when in viewport setting).
If we also could support the regular pager, all are still free to choose and we have the problem of directories (or ROOT) loading slow eliminated our self.
The idea of using direct entity queries would be an option for me, if loading times would increase dramatically ..
Anyway, who really needs to scroll thousands of medias, I always use the search. I can only imagine a special case, where I search for a thumbnail.
Comment #19
rang501 commentedThe issue is with sort I guess. We could add a pager, but because the sort direction seems to be oldest to newest, we can't see the last uploaded media which is most likely the one the user wants to select. It is an easy change.
As a user, I usually scroll down and select media there. Most of the time the media is not moved to the directory for various reasons.
I could take a quick look at how rendering with entity query could look like and give some performance differences. View performance is sometimes problematic, browsers most likely can handle rendering thousands of items just fine. Using entity query will lose some customizability some users need so we could add a setting for backend selection.
Comment #20
ytsurkGood point with the sort, did not think about, we should definitively to change to newest first, or even expose the sort with options alphabetical/newest first/oldest first.
As I said, I would not go with an entityquery and stay with views as it offers a lot of customization just via the UI (no code).
But still, if you want, check the difference, we can introduce another setting - entityquery/regular view ;)
Whereas a pager is needed anyway IMO, as making sense, and aligns with core.
Comment #21
dewalt commentedGuys, it could be funny to read "Unsure about pagination ... Locally, with 1000 media entities" in pager discussions if it isn't a problem. A view fully loads each entity, and having no pager its only a question of entities count and allowed memory when you'll get a "500: Allowed memory size ..." error.
After last module update the media_directories_base view was overridden in an update. Previously we customized the view with pager and sorts. And after the update we've got "Allowed memory size exhausted" error. We have 512M memory limit (higher than minimal recommended) and ~10 000 media entities only. It isn't much, I worked on projects where were hundreds of thousands media entities.
The pagination must be implemented. And looks like it is supported from the box - I've just added "full" pager into the view an everything works.
Comment #22
ytsurkYeah - this was 2021 with the mindset that we have directories (always showing everything like the file manager of your favorite OS),
and if I would have 100K of medias, I would have a ton of folders and not having all medias shown in root.
But no doubt, we will now add a pagination out of the box to reduce support in this direction.
The question remains, shall it be:
Whereas I vote for the custom pager.
And we should change sorting to newest first.
Comment #23
rang501 commentedI suggest something like this:
1. Change the sort order
2. Add normal full pager (to go to specific page easily) as default
3. Show 50(?) items per page
The next question would be how to make the update - just overwriting things we need or trying to detect custom changes?
Comment #24
dewalt commented@rang501 - the view already was fully overridden recently in media_directories_ui_update_9002(). It isn't good and was a surprise for us, but if it is already done I think it could be repeated.
Comment #25
rang501 commented@dewalt Updating configuration is complicated, we have two problems here -
1. If we update it, it will override customizations.
2. If we don't update it, users must do it manually which is probably more confusing.
It is hard to find the right balance and detecting if we need to update something is not reliable. We might be able to check if some pager or sort is already added and skip the update, but for more complex changes it is just too difficult to keep track of things.
Comment #26
ytsurkI would not introduce an update here.
This is for new installations, already running ones will have made their customization, eventually ;)
Comment #28
ytsurkI added now the full pager (with 18 items so we get 3 rows on desktops) and the sort (by changed, ascending).
Comment #29
ytsurkComment #30
rang501 commented@ytsurk
I think the page size should be larger and should reflect the maximum upload size limit, otherwise, we will have a situation, where the user uploads like 20 files, and some of them are on different pages. I did test it and after selecting 20 files, the field had only 18 added.
The default PHP limit for files is 20 and I think it's something that's changed less frequently than upload size.
Comment #31
rang501 commentedComment #32
ytsurkGood point - I really liked the fact of having three rows w/o scrolling :D
Why not make a warning on the status page, when you can upload more files then we display, with a recommendation to change the views pager size manually?
Comment #33
ytsurkI want to check how core media handles this case. As I already committed the changes to the -dev branch we need to hurry up here ...
I would not introduce any logic, like changing the pagination size on the fly for the view.
But I could imagine, just closing our media selector, and straight return to the field inserting all uploaded medias, fe.?
Further I think, we should provide an update path now (changed my mind) - only if the view does have the no pager configured.
Comment #34
ytsurkCore media has 24, so I suggest we take that.
An upgrade path will affect all that installed prior 2.2.2-beta4 (February 2024).
Does it make sense to do it for 2.2.0?
Comment #37
rang501 commentedClosing the issue. New 3.x handles this.