swingmx / swingmusic

Swing Music is a beautiful, self-hosted music player for your local audio files. Like a cooler Spotify ... but bring your own music.
https://swingmx.com
MIT License
731 stars 41 forks source link

Try multiprocessing on folders endpoint #57

Closed cwilvx closed 2 years ago

cwilvx commented 2 years ago

Apparently, I've discovered that there might be an issue if track tags are updated using other apps.

If tags are changed, we don't have any way of knowing. So, you'll still be seeing the old tags in the app. To fix this, I think we should try fetching the tags on demand for the folder endpoints.

This might not uniform (same response time for every endpoint) but it can be made faster by using either multiprocessing.Pool() or multithreading.ThreadPool(). Tests are need to see which is faster.

cwilvx commented 2 years ago

I used os.scandir to fetch tracks within that folder. Then those files are fetched from api.TRACKS list and returned. The folders are processed in a similar manner. Read by the scandir function and tracks in the folders counted and then returned.

Instead of using multiprocessing, using the smarter useBisection class to fetch them works wonders. Fetching 125 files takes 0.04s ... f*kn impressive.