From 53d8e2b0c3e07598a5d2c22f30f71ed16abed1bb Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 19 Dec 2024 16:43:05 +0530 Subject: [PATCH] chore: optimise webhooks payload --- src/Appwrite/Event/Webhook.php | 12 ++++++++++++ src/Appwrite/Platform/Workers/Webhooks.php | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Webhook.php b/src/Appwrite/Event/Webhook.php index 125c9a78d5..6457c53e68 100644 --- a/src/Appwrite/Event/Webhook.php +++ b/src/Appwrite/Event/Webhook.php @@ -14,4 +14,16 @@ class Webhook extends Event ->setQueue(Event::WEBHOOK_QUEUE_NAME) ->setClass(Event::WEBHOOK_CLASS_NAME); } + + public function trigger(): string|bool + { + /** Filter out context and trim project to keep the payload small */ + $this->context = []; + $this->project = [ + '$id' => $this->project->getId(), + '$internalId' => $this->project->getAttribute('internalId'), + ]; + + return parent::trigger(); + } } diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index ba0bdaa6a3..271c4c00f0 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -56,9 +56,10 @@ class Webhooks extends Action $events = $payload['events']; $webhookPayload = json_encode($payload['payload']); - $project = new Document($payload['project']); $user = new Document($payload['user'] ?? []); + $project = new Document($payload['project']); + $project = $dbForPlatform->getDocument('projects', $project->getId()); $log->addTag('projectId', $project->getId()); foreach ($project->getAttribute('webhooks', []) as $webhook) {