45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Remunerasi;
|
|
|
|
use App\Http\Controllers\Lainnya\SimulasiJabatan\SimulasiJabatanController;
|
|
use App\Models\Verifikator\Periode;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class WarmSimulasiJabatanCacheCommand extends Command
|
|
{
|
|
protected $signature = 'simulasi-jabatan:warm-cache {periode?}';
|
|
|
|
protected $description = 'Pra-hitung & cache dataset menu Lainnya > Simulasi Jabatan agar halaman terbuka ringan';
|
|
|
|
public function handle(): int
|
|
{
|
|
$periode = $this->argument('periode')
|
|
? Periode::where('id_periode', $this->argument('periode'))->first()
|
|
: Periode::where('status', true)->first();
|
|
|
|
if (! $periode) {
|
|
$this->error('Periode tidak ditemukan.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$id = (int) $periode->id_periode;
|
|
|
|
Cache::forget(SimulasiJabatanController::datasetCacheKey($id));
|
|
|
|
$start = microtime(true);
|
|
$rows = app(SimulasiJabatanController::class)->dataset($id);
|
|
|
|
$this->info(sprintf(
|
|
'Periode %d: %d baris di-cache (%.1fs).',
|
|
$id,
|
|
$rows->count(),
|
|
microtime(true) - $start
|
|
));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|