Skip to content

Commit

Permalink
Implemented caching for the ScanReports. Closed #173.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lednerb committed Oct 22, 2019
1 parent 334e70d commit 0fc74f4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/Http/Controllers/ScanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use App\Jobs\PushScanToElasticsearchJob;
use App\SiwecosScan;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Illuminate\Support\Facades\Cache;

class ScanController extends Controller
{
Expand Down Expand Up @@ -83,7 +84,10 @@ public function report(SiwecosScan $siwecosScan, $language = 'de')
if ($siwecosScan->is_freescan || $siwecosScan->domain->token == Token::whereToken(request()->header('SIWECOS-Token'))->first()) {
\App::setLocale($language);

return response()->json(new ScanReportResponse($siwecosScan->scans->first()));
$scan = $siwecosScan->scans->first();
return response()->json(Cache::rememberForever('scan-' . $scan->id, function () use ($scan) {
return new ScanReportResponse($scan);
}));
}

return response()->json(new StatusResponse('Forbidden'), 403);
Expand All @@ -94,7 +98,9 @@ public function reportV3(SiwecosScan $siwecosScan, $language = 'de')
if ($siwecosScan->is_freescan || $siwecosScan->domain->token == Token::whereToken(request()->header('SIWECOS-Token'))->first()) {
\App::setLocale($language);

return response()->json(new SiwecosScanReportResponse($siwecosScan));
return response()->json(Cache::rememberForever('siwecosScan-' . $siwecosScan->id, function () use ($siwecosScan) {
return new SiwecosScanReportResponse($siwecosScan);
}));
}

return response()->json(new StatusResponse('Forbidden'), 403);
Expand All @@ -108,7 +114,9 @@ public function pdfReport(SiwecosScan $siwecosScan, $language = 'de', Request $r
\App::setLocale($language);
$pdf = SnappyPdf::loadView('pdf.report', [
'scan' => $siwecosScan,
'report' => new ScanReportResponse($siwecosScan->scans->first()),
'report' => Cache::rememberForever('scan-' . $siwecosScan->scans->first(), function () use ($siwecosScan) {
return new ScanReportResponse($siwecosScan->scans->first());
}),
'gaugeData' => $this->getGaugeData($siwecosScan->scans->first())
]);
return $pdf->download('SIWECOS Scan Report.pdf');
Expand All @@ -131,7 +139,9 @@ public function pdfReportV3(SiwecosScan $siwecosScan, $language = 'de', Request
foreach ($siwecosScan->scans as $scan) {
$parts->push([
'scan' => $scan,
'report' => new ScanReportResponse($scan),
'report' => Cache::rememberForever('scan-' . $scan->id, function () use ($scan) {
return new ScanReportResponse($scan);
}),
'gaugeData' => $this->getGaugeData($scan)
]);
}
Expand Down

0 comments on commit 0fc74f4

Please sign in to comment.