Skip to content

refactor: improve channel handling for Realtime events and update tes…#11430

Merged
abnegate merged 3 commits into1.8.xfrom
realtime-tablesdb-prefix
Mar 2, 2026
Merged

refactor: improve channel handling for Realtime events and update tes…#11430
abnegate merged 3 commits into1.8.xfrom
realtime-tablesdb-prefix

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
Member

…ts for TablesDB compatibility

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

Event::mirrorCollectionEvents now returns a deduplicated, reindexed numeric array via array_values(array_unique(...)). The Realtime messaging adapter consolidates channel generation by merging legacy and tablesdb channel sources, adds a 'tablesdb' case in getDatabaseChannels, and removes prior per-prefix branching. Tests were expanded heavily: new/updated end-to-end realtime tests validate dual-prefix channel exposure (databases.* and tablesdb.*), require channels to be lists, and cover collection/table and document/row events, concurrency, and transactions. No public API signatures were changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description contains only template boilerplate without any actual details about the changes, test plan, or related issues, providing no meaningful information about the PR. Fill in the PR description template sections with specific details about what changes were made, how to test them, and any related issues or PRs.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main refactor: improving channel handling for Realtime events and updating tests for TablesDB compatibility, which aligns with the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch realtime-tablesdb-prefix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 2, 2026

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libecpg 18.1-r0 CVE-2026-2004 HIGH
libecpg 18.1-r0 CVE-2026-2005 HIGH
libecpg 18.1-r0 CVE-2026-2006 HIGH
libecpg 18.1-r0 CVE-2026-2007 HIGH
libecpg-dev 18.1-r0 CVE-2026-2004 HIGH
libecpg-dev 18.1-r0 CVE-2026-2005 HIGH
libecpg-dev 18.1-r0 CVE-2026-2006 HIGH
libecpg-dev 18.1-r0 CVE-2026-2007 HIGH
libheif 1.20.2-r1 CVE-2025-68431 HIGH
libpng 1.6.54-r0 CVE-2026-25646 HIGH
libpng-dev 1.6.54-r0 CVE-2026-25646 HIGH
libpq 18.1-r0 CVE-2026-2004 HIGH
libpq 18.1-r0 CVE-2026-2005 HIGH
libpq 18.1-r0 CVE-2026-2006 HIGH
libpq 18.1-r0 CVE-2026-2007 HIGH
libpq-dev 18.1-r0 CVE-2026-2004 HIGH
libpq-dev 18.1-r0 CVE-2026-2005 HIGH
libpq-dev 18.1-r0 CVE-2026-2006 HIGH
libpq-dev 18.1-r0 CVE-2026-2007 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2004 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2005 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2006 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2007 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Appwrite/Messaging/Adapter/Realtime.php`:
- Around line 514-519: The merged channel list in Realtime.php is creating
duplicate entries (e.g., 'rows') when combining results from getDatabaseChannels
into $channels; after merging the three arrays assigned to $channels,
deduplicate the merged array (preserving a clean list for emission) before it’s
used/returned—update the code around the $channels assignment that calls
getDatabaseChannels to filter out duplicate channel names (e.g., via a
unique/filter step) so each channel appears only once.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b03ad6d and 3d4f37c.

📒 Files selected for processing (3)
  • src/Appwrite/Event/Event.php
  • src/Appwrite/Messaging/Adapter/Realtime.php
  • tests/e2e/Services/Realtime/RealtimeCustomClientTest.php

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/Appwrite/Messaging/Adapter/Realtime.php (1)

514-519: ⚠️ Potential issue | 🟠 Major

Deduplicate merged channels before returning payload.

This merge still produces duplicates (notably rows) because it reindexes with array_values(...) but does not unique-filter the merged list.

🛠️ Proposed fix
-                    $channels = array_values(array_merge(
+                    $channels = array_values(array_unique(array_merge(
                         self::getDatabaseChannels('legacy', $database->getId(), $resourceId, $payload->getId(), 'databases'),
                         self::getDatabaseChannels('tablesdb', $database->getId(), $resourceId, $payload->getId(), 'databases'),
                         self::getDatabaseChannels('tablesdb', $database->getId(), $resourceId, $payload->getId())
-                    ));
+                    )));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Appwrite/Messaging/Adapter/Realtime.php` around lines 514 - 519, The
merged channel list assigned to $channels from multiple calls to
self::getDatabaseChannels(...) can contain duplicate entries (e.g., "rows");
after merging, filter duplicates before reindexing by applying a uniqueness
filter (e.g., array_unique) to the combined array, then call array_values to
reindex so $channels contains only distinct channel names; update the $channels
assignment where the three getDatabaseChannels calls are merged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/Appwrite/Messaging/Adapter/Realtime.php`:
- Around line 514-519: The merged channel list assigned to $channels from
multiple calls to self::getDatabaseChannels(...) can contain duplicate entries
(e.g., "rows"); after merging, filter duplicates before reindexing by applying a
uniqueness filter (e.g., array_unique) to the combined array, then call
array_values to reindex so $channels contains only distinct channel names;
update the $channels assignment where the three getDatabaseChannels calls are
merged.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4f37c and 82a5d13.

📒 Files selected for processing (2)
  • src/Appwrite/Event/Event.php
  • src/Appwrite/Messaging/Adapter/Realtime.php

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php (2)

126-127: Remove redundant list assertion in the same block.

assertIsList() already validates this; keeping both checks adds noise.

♻️ Proposed cleanup
-        $this->assertIsList($response['data']['channels']);
-        $this->assertTrue(array_is_list($response['data']['channels']));
+        $this->assertIsList($response['data']['channels']);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/Services/Realtime/RealtimeCustomClientTest.php` around lines 126 -
127, The test contains a redundant assertion: keep the built-in PHPUnit
assertion $this->assertIsList($response['data']['channels']) and remove the
duplicate check that calls array_is_list($response['data']['channels']) inside
$this->assertTrue(...); update the RealtimeCustomClientTest test method to
delete the line with $this->assertTrue(array_is_list(...)) so only
$this->assertIsList(...) remains.

823-824: Consider replacing repeated 8 with a named test constant.

The mirrored-channel count is asserted many times; a constant will make updates safer and easier.

♻️ Proposed refactor
 class RealtimeCustomClientTest extends Scope
 {
+    private const MIRRORED_DB_CHANNEL_COUNT = 8;
-        $this->assertCount(8, $response['data']['channels']);
+        $this->assertCount(self::MIRRORED_DB_CHANNEL_COUNT, $response['data']['channels']);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/Services/Realtime/RealtimeCustomClientTest.php` around lines 823 -
824, The test uses the magic number 8 repeatedly when asserting the mirrored
channel count; add a named test constant (e.g., EXPECTED_MIRRORED_CHANNEL_COUNT)
to the test class and replace literal usages of 8 in assertions like
$this->assertCount(8, $response['data']['channels']) and any other identical
assertions with self::EXPECTED_MIRRORED_CHANNEL_COUNT to centralize the value
and make future updates safer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/e2e/Services/Realtime/RealtimeCustomClientTest.php`:
- Around line 126-127: The test contains a redundant assertion: keep the
built-in PHPUnit assertion $this->assertIsList($response['data']['channels'])
and remove the duplicate check that calls
array_is_list($response['data']['channels']) inside $this->assertTrue(...);
update the RealtimeCustomClientTest test method to delete the line with
$this->assertTrue(array_is_list(...)) so only $this->assertIsList(...) remains.
- Around line 823-824: The test uses the magic number 8 repeatedly when
asserting the mirrored channel count; add a named test constant (e.g.,
EXPECTED_MIRRORED_CHANNEL_COUNT) to the test class and replace literal usages of
8 in assertions like $this->assertCount(8, $response['data']['channels']) and
any other identical assertions with self::EXPECTED_MIRRORED_CHANNEL_COUNT to
centralize the value and make future updates safer.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82a5d13 and 05a2f56.

📒 Files selected for processing (2)
  • src/Appwrite/Messaging/Adapter/Realtime.php
  • tests/e2e/Services/Realtime/RealtimeCustomClientTest.php

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 2, 2026

✨ Benchmark results

  • Requests per second: 1,709
  • Requests with 200 status code: 307,588
  • P99 latency: 0.096570143

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,709 1,162
200 307,588 209,229
P99 0.096570143 0.192262518

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 2, 2026

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit 05a2f56 - 3 flaky tests
Test Retries Total Time Details
UsageTest::testDatabaseStatsCollectionsAPI 1 10.14s Logs
LegacyTransactionsCustomServerTest::testBulkUpdate 1 240.58s Logs
TablesDBTransactionsConsoleClientTest::testPartialFailureRollback 1 240.61s Logs

@abnegate abnegate merged commit 5dadb9a into 1.8.x Mar 2, 2026
154 of 156 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants