Opening an image in a directory with many files is very slow
Describe the bug When opening an image in a directory with many (~10k) images, my browser hangs for about a minute. The longest time seems to be consumed by https://github.com/nextcloud/viewer/blob/c77de0393c22dbd294d6006d7ee4209e3c81d74d/src/views/Viewer.vue#L797-L799
The map() call here has a runtime complexity of O(n^2) with n being the number of files in the directory which is not ideal.
If I don't overlook something, the goal of
https://github.com/nextcloud/viewer/blob/c77de0393c22dbd294d6006d7ee4209e3c81d74d/src/views/Viewer.vue#L778-L799
is to get filteredFiles sorted and assign that to this.fileList.
From an algorithmic point of view, it should be possible that sortNodes() (or a similar function) returns a list of indices that sort the underlying list (here nodes) like argsort in NumPy. Then this list of indices can be used to reorder filteredFiles. Then, except for the sorting everything should run in O(n).
To Reproduce Steps to reproduce the behavior:
- Open an image in a directory with many (~10k) images
- Wait until the prev/next buttons appear
Desktop (please complete the following information):
- OS: Ubuntu 22.04
- Browser Firefox 144.0.2
Should be fixed once we have #2989