added wss tools 6
This commit is contained in:
@@ -68,9 +68,9 @@ class PriceStreamService
|
||||
return '';
|
||||
}
|
||||
|
||||
public function currentSeq(string $host): int
|
||||
public function currentSeq(): int
|
||||
{
|
||||
$inbox = Cache::get($this->inboxKey($host), ['seq' => 0, 'events' => []]);
|
||||
$inbox = Cache::get($this->inboxKey(), ['seq' => 0, 'events' => []]);
|
||||
|
||||
return (int) ($inbox['seq'] ?? 0);
|
||||
}
|
||||
@@ -78,9 +78,9 @@ class PriceStreamService
|
||||
/**
|
||||
* @return array<int, array{id: int, event: string, data: mixed}>
|
||||
*/
|
||||
public function consumeSince(string $host, int $afterId): array
|
||||
public function consumeSince(int $afterId): array
|
||||
{
|
||||
$inbox = Cache::get($this->inboxKey($host), ['seq' => 0, 'events' => []]);
|
||||
$inbox = Cache::get($this->inboxKey(), ['seq' => 0, 'events' => []]);
|
||||
$events = is_array($inbox['events'] ?? null) ? $inbox['events'] : [];
|
||||
|
||||
return array_values(array_filter(
|
||||
@@ -92,18 +92,13 @@ class PriceStreamService
|
||||
/**
|
||||
* @param array<string, mixed>|array<int, mixed> $data
|
||||
*/
|
||||
public function publish(string $event, array $data, ?string $host = null): void
|
||||
public function publish(string $event, array $data): void
|
||||
{
|
||||
if (! $this->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$host = $host ?? $this->resolveHost();
|
||||
if ($host === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$key = $this->inboxKey($host);
|
||||
$key = $this->inboxKey();
|
||||
$inbox = Cache::get($key, ['seq' => 0, 'events' => []]);
|
||||
$inbox['seq'] = (int) ($inbox['seq'] ?? 0) + 1;
|
||||
$inbox['events'][] = [
|
||||
@@ -119,9 +114,9 @@ class PriceStreamService
|
||||
Cache::put($key, $inbox, now()->addSeconds(self::INBOX_TTL_SECONDS));
|
||||
}
|
||||
|
||||
private function inboxKey(string $host): string
|
||||
private function inboxKey(): string
|
||||
{
|
||||
return self::INBOX_PREFIX.$this->normalizeHost($host);
|
||||
return self::INBOX_PREFIX.'global';
|
||||
}
|
||||
|
||||
private function normalizeHost(string $host): string
|
||||
|
||||
Reference in New Issue
Block a user