This commit is contained in:
Cüneyt Şentürk 2021-06-22 11:31:42 +03:00
parent 57b7cc904c
commit 4936995f2b
2 changed files with 24 additions and 14 deletions

View File

@ -59,19 +59,25 @@ class ReportCache extends Command
$reports = Report::orderBy('name')->get(); $reports = Report::orderBy('name')->get();
foreach ($reports as $report) { foreach ($reports as $report) {
$class = Utility::getClassInstance($report, false); try {
$class = Utility::getClassInstance($report, false);
if (empty($class)) { if (empty($class)) {
continue; continue;
}
$ttl = 3600 * 6; // 6 hours
Cache::forget('reports.totals.' . $report->id);
Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
return $class->getGrandTotal();
});
} catch (\Throwable $e) {
$this->error($e->getMessage());
report($e);
} }
$ttl = 3600 * 6; // 6 hours
Cache::forget('reports.totals.' . $report->id);
Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
return $class->getGrandTotal();
});
} }
} }
} }

View File

@ -51,8 +51,12 @@ class Version2117 extends Listener
protected function cacheReports() protected function cacheReports()
{ {
Report::all()->each(function ($report) { try {
Cache::put('reports.totals.' . $report->id, Utility::getClassInstance($report)->getGrandTotal()); Report::all()->each(function ($report) {
}); Cache::put('reports.totals.' . $report->id, Utility::getClassInstance($report)->getGrandTotal());
});
} catch (\Throwable $e) {
report($e);
}
} }
} }