From 85fec3ac82da8941866b15aaf9d4ba576c652e9e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 7 Sep 2026 00:55:08 -0600 Subject: [PATCH] Create PruneOldNotifications.php --- .../Commands/Admin/PruneOldNotifications.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/Console/Commands/Admin/PruneOldNotifications.php diff --git a/app/Console/Commands/Admin/PruneOldNotifications.php b/app/Console/Commands/Admin/PruneOldNotifications.php new file mode 100644 index 000000000..3283479a7 --- /dev/null +++ b/app/Console/Commands/Admin/PruneOldNotifications.php @@ -0,0 +1,50 @@ +subMonths((int) $this->option('months')); + $batch = max(100, (int) $this->option('batch')); + + $this->info("Pruning notifications older than {$cutoff->toDateTimeString()}"); + $this->info("Batch size: {$batch}"); + + $total = 0; + + do { + $deleted = DB::delete( + ' + DELETE FROM `notifications` + WHERE `created_at` < ? + ORDER BY `created_at` + LIMIT ? + ', + [$cutoff, $batch] + ); + + $total += $deleted; + + $this->line("Deleted {$deleted} rows ({$total} total)"); + + if ($deleted > 0) { + usleep(100_000); + } + } while ($deleted === $batch); + + $this->info("Finished. Deleted {$total} notifications."); + + return self::SUCCESS; + } +}