add webhook exist validation in bulkTrigger()#11022
Conversation
📝 WalkthroughWalkthroughThe change modifies the Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
…sert-webhook-validation
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php (2)
385-389: Move the webhook check outside the loop to avoid redundant evaluations.The condition
!empty($queueForEvents->getProject()->getAttribute('webhooks', []))is evaluated for every document in the loop. Since the project's webhook configuration doesn't change during the loop, this check can be performed once before entering the loop, improving efficiency for bulk operations with many documents.🔎 Proposed refactor to check webhooks once
+ $hasWebhooks = !empty($queueForEvents->getProject()->getAttribute('webhooks', [])); + foreach ($documents as $document) { $queueForEvents ->setParam('documentId', $document->getId()) ->setParam('rowId', $document->getId()) ->setPayload($document->getArrayCopy()); $queueForRealtime ->from($queueForEvents) ->trigger(); $queueForFunctions ->from($queueForEvents) ->trigger(); - if (!empty($queueForEvents->getProject()->getAttribute('webhooks', []))) { + if ($hasWebhooks) { $queueForWebhooks ->from($queueForEvents) ->trigger(); } }
392-395: Consider making webhook queue reset conditional to match trigger logic.When webhooks are not configured,
$queueForWebhooks->reset()is called at line 395 even though the webhook queue was not triggered in the loop. Since the queue is only modified when webhooks exist (line 385 condition), the reset can be made conditional to match the trigger pattern:if (!empty($queueForEvents->getProject()->getAttribute('webhooks', []))) { $queueForWebhooks->reset(); }This aligns with the principle that queues only require reset when they are actually triggered within a loop.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-12T04:07:12.576Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10800
File: src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php:153-154
Timestamp: 2025-11-12T04:07:12.576Z
Learning: In Appwrite's event queue system, `queueForRealtime`, `queueForFunctions`, and `queueForWebhooks` are copied from `queueForEvents`. Therefore, when resetting event queues in transaction staging paths, only `$queueForEvents->reset()` needs to be called in most cases. The other queues only require explicit reset when they are triggered in a loop.
Applied to files:
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php
🧬 Code graph analysis (1)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php (1)
src/Appwrite/Event/Event.php (1)
from(614-624)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: scan
✨ Benchmark results
⚡ Benchmark Comparison
|
No description provided.