patch: adds full page caching to TMBD & torrentio results
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
APP_ENV=%%app_env%%
|
||||
APP_SECRET="%%app_secret%%"
|
||||
DATABASE_URL="%%db_url%%"
|
||||
DOWNLOAD_DIR=%%download_dir%%
|
||||
|
||||
@@ -9,6 +9,8 @@ use App\Search\Action\Input\SearchInput;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
final class SearchController extends AbstractController
|
||||
{
|
||||
@@ -30,20 +32,25 @@ final class SearchController extends AbstractController
|
||||
|
||||
#[Route('/result/{mediaType}/{tmdbId}', name: 'app_search_result')]
|
||||
public function result(
|
||||
GetMediaInfoInput $getDownloadOptionsInput,
|
||||
GetMediaInfoInput $input,
|
||||
CacheInterface $cache
|
||||
): Response {
|
||||
$result = $this->getMediaInfoHandler->handle($getDownloadOptionsInput->toCommand());
|
||||
$cacheId = sprintf("page.%s.%s", $input->mediaType, $input->tmdbId);
|
||||
|
||||
return $this->render('search/result.html.twig', [
|
||||
'results' => $result,
|
||||
'filter' => [
|
||||
'resolution' => '',
|
||||
'codec' => '',
|
||||
'provider' => '',
|
||||
'language' => '',
|
||||
'season' => 1,
|
||||
'episode' => ''
|
||||
]
|
||||
]);
|
||||
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||
$item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
|
||||
$result = $this->getMediaInfoHandler->handle($input->toCommand());
|
||||
return $this->render('search/result.html.twig', [
|
||||
'results' => $result,
|
||||
'filter' => [
|
||||
'resolution' => '',
|
||||
'codec' => '',
|
||||
'provider' => '',
|
||||
'language' => '',
|
||||
'season' => 1,
|
||||
'episode' => ''
|
||||
]
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
final class TorrentioController extends AbstractController
|
||||
{
|
||||
@@ -28,12 +30,22 @@ final class TorrentioController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/torrentio/tvshows/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_torrentio_tvshows')]
|
||||
public function tvShowOptions(GetTvShowOptionsInput $input): Response
|
||||
public function tvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache): Response
|
||||
{
|
||||
$results = $this->getTvShowOptionsHandler->handle($input->toCommand());
|
||||
$cacheId = sprintf(
|
||||
"page.torrentio.tvshows.%s.%s.%s.%s",
|
||||
$input->tmdbId,
|
||||
$input->imdbId,
|
||||
$input->season,
|
||||
$input->episode,
|
||||
);
|
||||
|
||||
return $this->render('torrentio/tvshows.html.twig', [
|
||||
'results' => $results,
|
||||
]);
|
||||
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||
$item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
|
||||
$results = $this->getTvShowOptionsHandler->handle($input->toCommand());
|
||||
return $this->render('torrentio/tvshows.html.twig', [
|
||||
'results' => $results,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user