joshwcomeau / Tello

🐣 A simple and delightful way to track and manage TV shows.
https://tello.tv
331 stars 31 forks source link

Caching strategy #10

Open joshwcomeau opened 7 years ago

joshwcomeau commented 7 years ago

Right now, I'm accessing episode info straight from the TV Maze API. This means if you have 50 shows, on page-load I make 50 requests to TV Maze.

This is clearly not ideal, and it will likely upset the TV Maze folks if Tello continues to see actual usage.

My idea is fairly straightforward. I should add a new Mongo collection of show info, with episodes. This would be global, not connected to a specific user.

When a show is added, I check to see if the show exists. If it doesn't, I fetch it from TV Maze, and store the results in my database.

I'll need a cron job to run every night at midnight, and delete the entire collection. So the first request for a given show fetches it from TV Maze, but subsequent requests that day use the Mongo "cache".

But yeah, this is a lot of work, so I'm hesitant to do it until I need to.

morajabi commented 7 years ago

I'm doing this at subdl.com to minimize the API calls to tmdbapi.com. Yea, the mongo schema and mapping API JSON to that is a headache on its own :)