*/ private static array $queued = []; public static function queue(int ...$villageIds): void { foreach ($villageIds as $id) { self::$queued[$id] = true; } } public static function flush(): void { $ids = array_keys(self::$queued); self::$queued = []; self::villages($ids); } /** @param list $villageIds */ public static function villages(array $villageIds): void { if (! $villageIds || ! ws_available()) { return; } foreach (Village::with('player')->whereIn('id', $villageIds)->get() as $village) { $userId = $village->player?->user_id; try { $sockets = $userId ? WebsocketService::getUserSocketIds($userId) : []; if ($sockets) { ws_whisper('village:updated', ['village_id' => $village->id], $sockets); } } catch (Throwable $e) { // A push is a hint to refetch; the game state is already saved. report($e); } } } }