Accelerar listado ventas

This commit is contained in:
Juan Pablo Vial
2024-03-13 16:17:14 -03:00
parent 98953cce42
commit 8caa80459e
5 changed files with 70 additions and 8 deletions

View File

@ -74,6 +74,32 @@ class Ventas extends Controller
}
return $this->withJson($response, $output);
}
public function getMany(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta $service): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'ventas' => []
];
$ventas = explode(',', $body['ventas']);
foreach ($ventas as $venta_id) {
$redisKey = "venta:{$venta_id}";
try {
$venta = $this->fetchRedis($redisService, $redisKey);
$output['ventas'] []= $venta;
} catch (EmptyRedis) {
try {
$venta = $service->getById($venta_id);
$output['ventas'] []= $venta;
$this->saveRedis($redisService, $redisKey, $venta);
} catch (EmptyResult $exception) {
$this->logger->notice($exception);
}
}
}
return $this->withJson($response, $output);
}
public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Redis $redisService): ResponseInterface
{
$body = $request->getBody();