*/ private array $channels = []; /** @var array */ private array $pending = []; /** * @param list $uids */ public function request(array $uids): void { foreach ($uids as $uid) { if (Str::isUuid($uid) && ! array_key_exists($uid, $this->channels)) { $this->pending[$uid] = true; } } } public function get(?string $uid): ?Channel { if ($uid === null || ! Str::isUuid($uid)) { return null; } if (! array_key_exists($uid, $this->channels)) { $this->pending[$uid] = true; } $this->flush(); return $this->channels[$uid] ?? null; } private function flush(): void { if ($this->pending === []) { return; } $uids = array_keys($this->pending); $this->pending = []; $found = Channel::whereIn('uid', $uids) ->get(['uid', 'name', 'type', 'lang', 'owner_uid']) ->keyBy(fn (Channel $channel) => (string) $channel->uid); foreach ($uids as $uid) { $this->channels[$uid] = $found->get($uid); } } }