get(Setting::NotificationRetentionDays); if ($days <= 0) { $this->info('Notification retention is disabled; nothing pruned.'); return self::SUCCESS; } // Chunked for the same reason the API request log is: this is a // high-volume table, and a single unbounded DELETE on a busy // installation holds locks for as long as it takes. $cutoff = now()->subDays($days); $deleted = 0; do { $batch = InAppNotification::query() ->whereNotNull('read_at') ->where('created_at', '<', $cutoff) ->limit(5000) ->delete(); $deleted += $batch; } while ($batch > 0); $this->info("Pruned {$deleted} read notifications older than {$days} days."); return self::SUCCESS; } }