option('user')) { $this->refreshUser($userId); return Command::SUCCESS; } // Refresh all users with stale stats (> 1 hour old) $staleUsers = User::where(function ($query) { $query->whereNull('stats_computed_at') ->orWhere('stats_computed_at', '<', now()->subHour()); })->pluck('id'); $this->info("Queuing stats refresh for {$staleUsers->count()} users..."); foreach ($staleUsers as $userId) { ComputeUserStats::dispatch($userId)->onQueue('stats'); } $this->info('Done! Stats will be computed in background.'); return Command::SUCCESS; } protected function refreshUser(int $userId): void { $user = User::find($userId); if (! $user) { $this->error("User {$userId} not found."); return; } $this->info("Computing stats for user: {$user->name}..."); ComputeUserStats::dispatchSync($userId); $this->info('Done!'); } }