feat: Eagerly load and cache playlists #27
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Eagerly Generate Playlist and Store in a Cache
Playlists are taking a long time to load. For more, see Issue #25.
Features
🆕 Class -
PlaylistCache
- Stores entire playlistsfunction createPlaylistKey(users: [number, number], preferenceType: PreferenceType): string
Dependency -
lru-cache
This library looks well supported.
🆕 Functionality -
Playlist Service
looks for cached playlists before generating new onesHighlight - It looks for both the requested playlist and the inverse playlist
When a playlist is requested,
Impact - The site appears 10-20x faster
Caveat - No speed up provided if the pre-load has not completed
Approach for Future Optimization - Cache the pending preload function and return it
The preload call already kicks off 3 playlist generation calls. We can store those pending functions in a cache. If those playlists are requested while the calls are pending, we can add some kind of
callback
to the pending function so that just wait for the previous calls to finish, rather than kick off new requests.Benchmarks are approximate
These numbers are approximate, based on informal benchmarking.