From cbe13d71f1146cdc0dd47043ea731a6d0d76d445 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 28 Jan 2026 19:04:42 +0530 Subject: [PATCH] removed redundant key --- src/Appwrite/Messaging/Adapter/Realtime.php | 19 ++++++++++--------- .../RealtimeCustomClientQueryTest.php | 10 +++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Appwrite/Messaging/Adapter/Realtime.php b/src/Appwrite/Messaging/Adapter/Realtime.php index 35c6e9c710..6dbfa7c7dc 100644 --- a/src/Appwrite/Messaging/Adapter/Realtime.php +++ b/src/Appwrite/Messaging/Adapter/Realtime.php @@ -231,18 +231,19 @@ class Realtime extends MessagingAdapter $payload = $event['data']['payload'] ?? []; foreach ($this->subscriptions[$event['project']][$role][$channel] as $id => $queryMap) { $matchedQueryKeys = []; - // for representing a all query subscribed channel if (isset($queryMap[''])) { - $matchedQueryKeys[] = ''; - } else { - foreach (array_keys($queryMap) as $queryKey) { - $parsed = Query::parseQueries([$queryKey]); - if (!empty(RuntimeQuery::filter($parsed, $payload))) { - $matchedQueryKeys[] = $queryKey; - } + $receivers[$id] = $matchedQueryKeys; + continue; + } + foreach (array_keys($queryMap) as $queryKey) { + $parsed = Query::parseQueries([$queryKey]); + if (!empty(RuntimeQuery::filter($parsed, $payload))) { + $matchedQueryKeys[] = $queryKey; } } - $receivers[$id] = $matchedQueryKeys; + if (!empty($matchedQueryKeys)) { + $receivers[$id] = $matchedQueryKeys; + } } break; } diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientQueryTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientQueryTest.php index f69ef187e5..72a589062b 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientQueryTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientQueryTest.php @@ -1608,7 +1608,7 @@ class RealtimeCustomClientQueryTest extends Scope Query::equal('category', ['gold']), ])->toString(); - // Subscribe with no queries -> should receive all events, queryKeys = [''] + // Subscribe with no queries -> should receive all events, queryKeys = [] $clientAll = $this->getWebsocket(['documents'], [ 'origin' => 'http://localhost', 'cookie' => 'a_session_' . $projectId . '=' . $session, @@ -1660,13 +1660,13 @@ class RealtimeCustomClientQueryTest extends Scope ], ]); - // clientAll: should receive event, queryKeys = [''] + // clientAll: should receive event, queryKeys = [] $eventAll = json_decode($clientAll->receive(), true); $this->assertEquals('event', $eventAll['type']); $this->assertEquals($docActiveGoldId, $eventAll['data']['payload']['$id']); $this->assertArrayHasKey('queryKeys', $eventAll['data']); $this->assertIsArray($eventAll['data']['queryKeys']); - $this->assertEquals([''], $eventAll['data']['queryKeys']); + $this->assertCount(0, $eventAll['data']['queryKeys']); // clientQ1: should receive event, queryKeys contains queryStatusActive $eventQ1 = json_decode($clientQ1->receive(), true); @@ -1704,13 +1704,13 @@ class RealtimeCustomClientQueryTest extends Scope ], ]); - // clientAll: should receive event, queryKeys = [''] + // clientAll: should receive event, queryKeys = [] $eventAll2 = json_decode($clientAll->receive(), true); $this->assertEquals('event', $eventAll2['type']); $this->assertEquals($docPendingSilverId, $eventAll2['data']['payload']['$id']); $this->assertArrayHasKey('queryKeys', $eventAll2['data']); $this->assertIsArray($eventAll2['data']['queryKeys']); - $this->assertEquals([''], $eventAll2['data']['queryKeys']); + $this->assertCount(0, $eventAll2['data']['queryKeys']); // clientQ1: should NOT receive event (status is pending) try {