From cf99269bc55a6ce2efd57a45778e453547eb3c2b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 1 Apr 2026 18:08:45 +0530 Subject: [PATCH] Add reset method to Realtime class for clearing event state This new method resets the event state for long-lived worker processes by clearing subscribers, context, and user-related fields, ensuring no stale state affects subsequent triggers. --- src/Appwrite/Event/Realtime.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Appwrite/Event/Realtime.php b/src/Appwrite/Event/Realtime.php index 747fd786f9..f040d91468 100644 --- a/src/Appwrite/Event/Realtime.php +++ b/src/Appwrite/Event/Realtime.php @@ -61,6 +61,26 @@ class Realtime extends Event return $this->subscribers; } + /** + * Reset the event state for long-lived worker processes. + * + * `Event::reset()` clears params/sensitive/event/payload only. Realtime routing also + * depends on `context`, `subscribers`, and `project`/`user` fields, so we clear them too + * to prevent stale state from affecting subsequent triggers. + */ + public function reset(): self + { + parent::reset(); + + $this->subscribers = []; + $this->context = []; + $this->project = null; + $this->user = null; + $this->userId = null; + + return $this; + } + /** * Execute Event. *