griff / metaz

Two letters better than MetaX
https://metaz.maven-group.org/
MIT License
411 stars 56 forks source link

Remote data download improvements (multithread, caching) #260

Closed dagronf closed 2 years ago

dagronf commented 2 years ago

This patch adds two performance improvements when working with download search result data (posters)

  1. Added a URLSession cache for remote data downloading.

When working with a tv series, I found that the loading of the poster information for each tv episode re-loads ALL of the posters for the series for each episode, even if the poster data URL was the same for the previously selected episode.

This adds a URL cache to the URLSession to avoid re-downloading data for the same URL (ive fixed the cache size to 128 meg) makes working with an entire TV series a MUCH smoother experience.

For example, for a 'popular' tv series, seeing the first poster for a selected search result might take 10-20 seconds (as it was downloading 20-30 posters in the background before displaying). For each episode in the series, it would re-download the same URL data for the posters. Adding the cache here means it is only downloaded once.

  1. Support multithreaded downloads for RemoteData

All posters for a search selection are downloaded before the first one is shown in the UI. For popular tv series, there can be 20 or more posters for the series which are all downloaded before the 'first' poster appears in the UI. Currently, the posters are downloaded serially which means that on a slow-ish connection to tvDB (for eg) this can take quite a while before the 'first' poster appears in the UI.

This patch moves patch downloading onto the global 'utility' thread which allows for multiple simultaneous downloads, limiting the number of simultaneous downloads to 10.

griff commented 2 years ago

Thanks for this PR it is much appreciated. I will try and get this released as soon as possible.