At the moment, this PR only applies the first fix I detailed in #129. @davwheat can take a look and let me know if it fixes the issue, and if there's still some performance to be desired, I'll work on implementing the rest of the fixes.
[x] Most likely, if you run ls -la on that directory right now, it won't take 5 minutes. This makes this problem a bit more confusing, since ls will be fetching the same information that we are. My guess is that since we use finfo_file to read file info to determine whether to draw a tooltip, that's the main bottleneck. Since finfo reads MIME types, it has to open and read the first few bytes of each file, which is much slower than just getting info like size from the file system. This can be fixed by just checking via file extension.
[ ] It's reasonable to suspect that reading file info might be slow itself even without finfo_file. This could be fixed by creating an index of all uploads that has some basic info about each file. This means that the page will just have to read from the index instead of scanning the directory each time. The index would be updated whenever a file is uploaded, renamed, or deleted. This means that users wouldn't be able to really change the files manually, because it would break the index. In addition to generating the index on first load, users could be given the object to regenerate the index if they have to change something (like with a button on the dashboard). Index mode would be an off-by-default configuration option.
[ ] Finally, there's likely a performance drawback from generating all the HTML for the data table at once and sending it over. Luckily, DataTables allows for server side processing. This means that server would be doing all the sorting and would just send over the rows to display. Using this along with index mode would greatly speed up time to first byte, as well as page load time. This would also be in a configuration option.
Fixes #129.
At the moment, this PR only applies the first fix I detailed in #129. @davwheat can take a look and let me know if it fixes the issue, and if there's still some performance to be desired, I'll work on implementing the rest of the fixes.