where('online_count', '>', 0) ->where('last_online_at', '<', now()->subMinutes(5)) ->chunkById(1000, function ($users) use (&$affected) { if ($users->isEmpty()) { return; } $count = User::whereIn('id', $users->pluck('id')) ->update(['online_count' => 0]); $affected += $count; }, 'id'); $this->info("Expired online status cleaned. Affected: {$affected}"); return self::SUCCESS; } catch (\Throwable $e) { Log::error('CleanupExpiredOnlineStatus failed', ['error' => $e->getMessage()]); $this->error('Cleanup failed: ' . $e->getMessage()); return self::FAILURE; } } }