You can use the Cache to retrieve the screenshot from your Episode model.
Optimize image loading iteration
I have a laravel application in which the user is presented with a list of episodes, each with a screenshot. Each screenshot is loaded inside a foreach loop in the view as per this pseudo code:
foreach $episodes as $episode
$episode->getScreenshot($episodeID);
endforeach
The getScreenshot() method resolves a specific ScreenshotLocator class out of the IoC container like so:
$screenshotLocator = App::make('\Animekyun\Images\Screenshots\ScreenshotLocator');
(I'm reading some things about binding it to the container as a singleton. Is that something to consider? Currently it's not bound at all)
The ScreenshotLocator class is designed to build the path to the actual screenshots folder (source below) using the Episode model. The screenshots (there are multiple per episode) are all stored in a folder structure and the necessary files are loaded and stored in a Collection.
The loading of the screenshots takes 40 ms out of the 135 ms for the entire page to load on a Digital Ocean droplet. (10x run benchmark). Note, with loading I mean from Boot to After. Not the actual HTTP requests
So my question is what are some ways to optimize this?
Source for the ScreenshotLocator class:
http://laravel.io/bin/6L19r
Please or to participate in this conversation.