From 03b0a62a22ac71c42243bf434cbfd005af2156b5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 19 Dec 2021 01:25:49 -0700 Subject: [PATCH] Update console kernel, add db session garbage collector that runs twice daily --- .../DatabaseSessionGarbageCollector.php | 56 +++++++++++++++++++ app/Console/Kernel.php | 1 + 2 files changed, 57 insertions(+) create mode 100644 app/Console/Commands/DatabaseSessionGarbageCollector.php diff --git a/app/Console/Commands/DatabaseSessionGarbageCollector.php b/app/Console/Commands/DatabaseSessionGarbageCollector.php new file mode 100644 index 000000000..db11cb80d --- /dev/null +++ b/app/Console/Commands/DatabaseSessionGarbageCollector.php @@ -0,0 +1,56 @@ +whereNull('user_id')->delete(); + }); + + DB::transaction(function() { + $ts = now()->subMonths(3)->timestamp; + DB::table('sessions')->where('last_activity', '<', $ts)->delete(); + }); + + return Command::SUCCESS; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 0dd65888a..dd1bae944 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -31,6 +31,7 @@ class Kernel extends ConsoleKernel $schedule->command('story:gc')->everyFiveMinutes(); $schedule->command('gc:failedjobs')->dailyAt(3); $schedule->command('gc:passwordreset')->dailyAt('09:41'); + $schedule->command('gc:sessions')->twiceDaily(13, 23); } /**