feat: allows configuring whether to cache torrentio results
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 13s
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 13s
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Torrentio\Framework\Controller;
|
||||
|
||||
use App\Base\ConfigResolver;
|
||||
use App\Base\Service\Broadcaster;
|
||||
use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
||||
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
||||
@@ -27,6 +28,7 @@ final class WebController extends AbstractController
|
||||
public function __construct(
|
||||
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
||||
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
||||
private readonly ConfigResolver $configResolver,
|
||||
private readonly Broadcaster $broadcaster,
|
||||
) {}
|
||||
|
||||
@@ -40,10 +42,14 @@ final class WebController extends AbstractController
|
||||
$input->imdbId
|
||||
);
|
||||
|
||||
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) {
|
||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||
return $this->getMovieOptionsHandler->handle($input->toCommand());
|
||||
});
|
||||
if (true === $this->configResolver->isTorrentioCacheEnabled()) {
|
||||
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) {
|
||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||
return $this->getMovieOptionsHandler->handle($input->toCommand());
|
||||
});
|
||||
} else {
|
||||
$results = $this->getMovieOptionsHandler->handle($input->toCommand());
|
||||
}
|
||||
|
||||
if ($request->headers->get('Turbo-Frame')) {
|
||||
return $this->sendFragmentResponse($results, $request);
|
||||
@@ -66,10 +72,14 @@ final class WebController extends AbstractController
|
||||
);
|
||||
|
||||
try {
|
||||
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||
return $this->getTvShowOptionsHandler->handle($input->toCommand());
|
||||
});
|
||||
if (true === $this->configResolver->isTorrentioCacheEnabled()) {
|
||||
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||
return $this->getTvShowOptionsHandler->handle($input->toCommand());
|
||||
});
|
||||
} else {
|
||||
$results = $this->getTvShowOptionsHandler->handle($input->toCommand());
|
||||
}
|
||||
|
||||
if ($request->headers->get('Turbo-Frame')) {
|
||||
return $this->sendFragmentResponse($results, $request);
|
||||
|
||||
Reference in New Issue
Block a user