adambechtold / taste-explorer

1 stars 1 forks source link

feat: Eagerly load and cache playlists #27

Closed adambechtold closed 8 months ago

adambechtold commented 8 months ago

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 playlists

Dependency - lru-cache

This library looks well supported.

🆕 Functionality - Playlist Service looks for cached playlists before generating new ones

Highlight - It looks for both the requested playlist and the inverse playlist

When a playlist is requested,

1) Look for a playlist the fits the exact parameters 2) Look for a playlist that fits the inverse parameters

image

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.