patch: adds full page caching to TMBD & torrentio results

This commit is contained in:
2025-05-01 21:46:14 -05:00
parent 687b5ed873
commit 12bf90a2b4
3 changed files with 38 additions and 18 deletions

View File

@@ -1,3 +1,4 @@
APP_ENV=%%app_env%%
APP_SECRET="%%app_secret%%" APP_SECRET="%%app_secret%%"
DATABASE_URL="%%db_url%%" DATABASE_URL="%%db_url%%"
DOWNLOAD_DIR=%%download_dir%% DOWNLOAD_DIR=%%download_dir%%

View File

@@ -9,6 +9,8 @@ use App\Search\Action\Input\SearchInput;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
final class SearchController extends AbstractController final class SearchController extends AbstractController
{ {
@@ -30,20 +32,25 @@ final class SearchController extends AbstractController
#[Route('/result/{mediaType}/{tmdbId}', name: 'app_search_result')] #[Route('/result/{mediaType}/{tmdbId}', name: 'app_search_result')]
public function result( public function result(
GetMediaInfoInput $getDownloadOptionsInput, GetMediaInfoInput $input,
CacheInterface $cache
): Response { ): Response {
$result = $this->getMediaInfoHandler->handle($getDownloadOptionsInput->toCommand()); $cacheId = sprintf("page.%s.%s", $input->mediaType, $input->tmdbId);
return $this->render('search/result.html.twig', [ return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
'results' => $result, $item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
'filter' => [ $result = $this->getMediaInfoHandler->handle($input->toCommand());
'resolution' => '', return $this->render('search/result.html.twig', [
'codec' => '', 'results' => $result,
'provider' => '', 'filter' => [
'language' => '', 'resolution' => '',
'season' => 1, 'codec' => '',
'episode' => '' 'provider' => '',
] 'language' => '',
]); 'season' => 1,
'episode' => ''
]
]);
});
} }
} }

View File

@@ -9,6 +9,8 @@ use App\Torrentio\Action\Input\GetTvShowOptionsInput;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
final class TorrentioController extends AbstractController 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')] #[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', [ return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
'results' => $results, $item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
]); $results = $this->getTvShowOptionsHandler->handle($input->toCommand());
return $this->render('torrentio/tvshows.html.twig', [
'results' => $results,
]);
});
} }
} }