updates)) { return; } collect($this->updates) ->chunk(1000) ->each(function (Collection $chunk) { $userIds = $chunk->pluck('id')->all(); User::query() ->whereIn('id', $userIds) ->each(function (User $user) use ($chunk) { $update = $chunk->firstWhere('id', $user->id); if ($update) { $user->update([ 'online_count' => $update['count'], 'last_online_at' => now(), ]); } }); }); } /** * 任务失败的处理 */ public function failed(\Throwable $exception): void { \Log::error('Failed to sync user online status', [ 'error' => $exception->getMessage(), 'updates_count' => count($this->updates) ]); } }