Optimizacion de queries a cargar de una sola vez

This commit is contained in:
Juan Pablo Vial
2025-04-22 09:28:12 -04:00
parent fc776e6cec
commit 33b4182bd3
8 changed files with 223 additions and 52 deletions

View File

@ -168,18 +168,10 @@ class Contracts
if (is_string($unit_ids)) {
$unit_ids = json_decode($input['unidad_ids'], true);
}
foreach ($unit_ids as $unit_id) {
try {
$unit = $unitRepository->fetchById($unit_id);
$contractService->getById($contract_id);
$promotions = $promotionRepository->fetchByContractAndUnit($contract_id, $unit->id);
$output['unidades'] []= [
'id' => $unit->id,
'promotions' => $promotions
];
} catch (ServiceAction\Read | Implement\Exception\EmptyResult $exception) {
$logger->debug($exception);
}
try {
$output['unidades'] = $promotionRepository->fetchByContractAndUnits($contract_id, $unit_ids);
} catch (Implement\Exception\EmptyResult $exception) {
$logger->debug($exception);
}
return $this->withJson($response, $output);
}