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:
3
.env
3
.env
@@ -68,3 +68,6 @@ SENTRY_JS_URL=
|
|||||||
# - only include media originally
|
# - only include media originally
|
||||||
# produced in this language
|
# produced in this language
|
||||||
TMDB_ORIGINAL_LANGUAGE=en
|
TMDB_ORIGINAL_LANGUAGE=en
|
||||||
|
|
||||||
|
# Cache Torrentio Results
|
||||||
|
TORRENTIO_CACHE_RESULTS=true
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ parameters:
|
|||||||
sentry.dsn: '%env(SENTRY_DSN)%'
|
sentry.dsn: '%env(SENTRY_DSN)%'
|
||||||
sentry.javascript_url: '%env(SENTRY_JS_URL)%'
|
sentry.javascript_url: '%env(SENTRY_JS_URL)%'
|
||||||
|
|
||||||
|
# Torrentio
|
||||||
|
torrentio.cache_results: '%env(bool:TORRENTIO_CACHE_RESULTS)%'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# default configuration for services in *this* file
|
# default configuration for services in *this* file
|
||||||
_defaults:
|
_defaults:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Base;
|
|||||||
|
|
||||||
use App\Base\Dto\AppVersionDto;
|
use App\Base\Dto\AppVersionDto;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
|
|
||||||
final class ConfigResolver
|
final class ConfigResolver
|
||||||
@@ -14,6 +15,7 @@ final class ConfigResolver
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly DenormalizerInterface $denormalizer,
|
private readonly DenormalizerInterface $denormalizer,
|
||||||
|
private readonly RequestStack $requestStack,
|
||||||
|
|
||||||
#[Autowire(param: 'app.url')]
|
#[Autowire(param: 'app.url')]
|
||||||
private readonly ?string $appUrl = null,
|
private readonly ?string $appUrl = null,
|
||||||
@@ -62,6 +64,9 @@ final class ConfigResolver
|
|||||||
|
|
||||||
#[Autowire(param: 'sentry.javascript_url')]
|
#[Autowire(param: 'sentry.javascript_url')]
|
||||||
private ?string $sentryJavascriptUrl = null,
|
private ?string $sentryJavascriptUrl = null,
|
||||||
|
|
||||||
|
#[Autowire(param: 'torrentio.cache_results')]
|
||||||
|
private ?bool $torrentioCacheResults = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function validate(): bool
|
public function validate(): bool
|
||||||
@@ -110,6 +115,11 @@ final class ConfigResolver
|
|||||||
return $this->authOidcBypassFormLogin;
|
return $this->authOidcBypassFormLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isTorrentioCacheEnabled(): bool
|
||||||
|
{
|
||||||
|
return $this->torrentioCacheResults;
|
||||||
|
}
|
||||||
|
|
||||||
public function getAppVersion(): AppVersionDto
|
public function getAppVersion(): AppVersionDto
|
||||||
{
|
{
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Torrentio\Framework\Controller;
|
namespace App\Torrentio\Framework\Controller;
|
||||||
|
|
||||||
|
use App\Base\ConfigResolver;
|
||||||
use App\Base\Service\Broadcaster;
|
use App\Base\Service\Broadcaster;
|
||||||
use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
||||||
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
||||||
@@ -27,6 +28,7 @@ final class WebController extends AbstractController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
||||||
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
||||||
|
private readonly ConfigResolver $configResolver,
|
||||||
private readonly Broadcaster $broadcaster,
|
private readonly Broadcaster $broadcaster,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -40,10 +42,14 @@ final class WebController extends AbstractController
|
|||||||
$input->imdbId
|
$input->imdbId
|
||||||
);
|
);
|
||||||
|
|
||||||
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) {
|
if (true === $this->configResolver->isTorrentioCacheEnabled()) {
|
||||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) {
|
||||||
return $this->getMovieOptionsHandler->handle($input->toCommand());
|
$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')) {
|
if ($request->headers->get('Turbo-Frame')) {
|
||||||
return $this->sendFragmentResponse($results, $request);
|
return $this->sendFragmentResponse($results, $request);
|
||||||
@@ -66,10 +72,14 @@ final class WebController extends AbstractController
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
if (true === $this->configResolver->isTorrentioCacheEnabled()) {
|
||||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
$results = $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||||
return $this->getTvShowOptionsHandler->handle($input->toCommand());
|
$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')) {
|
if ($request->headers->get('Turbo-Frame')) {
|
||||||
return $this->sendFragmentResponse($results, $request);
|
return $this->sendFragmentResponse($results, $request);
|
||||||
|
|||||||
Reference in New Issue
Block a user