From dc2845d74d1be7f67c5dc764ac22397249f6296e Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Wed, 16 Jul 2025 20:11:30 -0500 Subject: [PATCH] fix: bad caching causing turbo frames not to reload properly --- .../Handler/GetTvShowOptionsHandler.php | 3 +- .../Action/Result/GetTvShowOptionsResult.php | 4 +- .../Framework/Controller/WebController.php | 42 ++++++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php b/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php index 825d0e6..0885c8c 100644 --- a/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php +++ b/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php @@ -3,6 +3,7 @@ namespace App\Torrentio\Action\Handler; use App\Base\Service\MediaFiles; +use App\Library\Dto\MediaFileDto; use App\Tmdb\Tmdb; use App\Torrentio\Action\Command\GetTvShowOptionsCommand; use App\Torrentio\Action\Result\GetTvShowOptionsResult; @@ -28,7 +29,7 @@ class GetTvShowOptionsHandler implements HandlerInterface return new GetTvShowOptionsResult( media: $media, - file: $file, + file: MediaFileDto::fromSplFileInfo($file), season: $command->season, episode: $command->episode, results: $this->torrentio->fetchEpisodeResults( diff --git a/src/Torrentio/Action/Result/GetTvShowOptionsResult.php b/src/Torrentio/Action/Result/GetTvShowOptionsResult.php index d379c66..e3014c4 100644 --- a/src/Torrentio/Action/Result/GetTvShowOptionsResult.php +++ b/src/Torrentio/Action/Result/GetTvShowOptionsResult.php @@ -2,15 +2,15 @@ namespace App\Torrentio\Action\Result; +use App\Library\Dto\MediaFileDto; use App\Tmdb\TmdbResult; use OneToMany\RichBundle\Contract\ResultInterface; -use Symfony\Component\Finder\SplFileInfo; class GetTvShowOptionsResult implements ResultInterface { public function __construct( public TmdbResult $media, - public bool|SplFileInfo $file, + public bool|MediaFileDto $file, public string $season, public string $episode, public array $results diff --git a/src/Torrentio/Framework/Controller/WebController.php b/src/Torrentio/Framework/Controller/WebController.php index acb3e06..1ecce02 100644 --- a/src/Torrentio/Framework/Controller/WebController.php +++ b/src/Torrentio/Framework/Controller/WebController.php @@ -13,6 +13,7 @@ use OneToMany\RichBundle\Contract\ResultInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\Cache; use Symfony\Component\Routing\Attribute\Route; use Symfony\Contracts\Cache\CacheInterface; use Symfony\Contracts\Cache\ItemInterface; @@ -26,6 +27,7 @@ final class WebController extends AbstractController private readonly Broadcaster $broadcaster, ) {} + #[Cache(expires: 3600, public: false, mustRevalidate: true)] #[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')] public function movieOptions(GetMovieOptionsInput $input, CacheInterface $cache, Request $request): Response { @@ -35,18 +37,18 @@ final class WebController extends AbstractController $input->imdbId ); - return $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) { + $results = $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) { $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); - $results = $this->getMovieOptionsHandler->handle($input->toCommand()); - - if ($request->headers->get('Turbo-Frame')) { - return $this->sendFragmentResponse($results, $request); - } - - return $this->render('torrentio/movies.html.twig', [ - 'results' => $results, - ]); + return $this->getMovieOptionsHandler->handle($input->toCommand()); }); + + if ($request->headers->get('Turbo-Frame')) { + return $this->sendFragmentResponse($results, $request); + } + + return $this->render('torrentio/movies.html.twig', [ + 'results' => $results, + ]); } #[Route('/torrentio/tvshows/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_torrentio_tvshows')] @@ -61,18 +63,18 @@ final class WebController extends AbstractController ); try { - return $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) { + $results = $cache->get($cacheId, function (ItemInterface $item) use ($input) { $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); - $results = $this->getTvShowOptionsHandler->handle($input->toCommand()); - - if ($request->headers->get('Turbo-Frame')) { - return $this->sendFragmentResponse($results, $request); - } - - return $this->render('torrentio/tvshows.html.twig', [ - 'results' => $results, - ]); + return $this->getTvShowOptionsHandler->handle($input->toCommand()); }); + + if ($request->headers->get('Turbo-Frame')) { + return $this->sendFragmentResponse($results, $request); + } + + return $this->render('torrentio/tvshows.html.twig', [ + 'results' => $results, + ]); } catch (TorrentioRateLimitException $exception) { $this->broadcaster->alert('Warning', 'Torrentio has rate limited your requests. Please wait a few minutes before trying again.', 'warning'); return $this->render('bare.html.twig',