Skip to content

chore: lazy init sms adapter + late static binding#10961

Merged
abnegate merged 1 commit into1.8.xfrom
refactor-messaging-and-queue
Dec 16, 2025
Merged

chore: lazy init sms adapter + late static binding#10961
abnegate merged 1 commit into1.8.xfrom
refactor-messaging-and-queue

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

@ChiragAgg5k ChiragAgg5k commented Dec 16, 2025

  1. prevents initing of sms adapter in all workers:
Screenshot 2025-12-16 at 10 37 14 AM
  1. late static binding helps fix type errors in queues, for eg here:
Screenshot 2025-12-16 at 10 38 06 AM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 16, 2025

📝 Walkthrough

Walkthrough

This pull request updates several return type declarations from self to static in setter methods of src/Appwrite/Event/Event.php and src/Appwrite/Event/Database.php. It removes the setProject(Document $project) method from src/Appwrite/Event/Messaging.php. In src/Appwrite/Platform/Workers/Messaging.php the internal SMS adapter initialization was changed from eager (constructor) to lazy (created on first use in sendInternalSMSMessage), preserving the existing null-check and fallback warning behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Verify that changing return types from self to static does not break fluent interfaces or subclassing behavior where these setters are used.
  • Confirm removal of Event\Messaging::setProject does not leave callers broken or rely on the property being set elsewhere.
  • Inspect lazy initialization in Platform\Workers\Messaging::sendInternalSMSMessage for thread-safety/race conditions (if used concurrently) and that warning/fallback remains correct.
  • Quick pass for PHPDoc updates and any downstream callsites that depend on the previous method signatures.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main changes: lazy initialization of the SMS adapter and introduction of late static binding for type safety.
Description check ✅ Passed The description relates to the changeset by explaining the purpose of the SMS adapter lazy initialization and late static binding improvements, with supporting screenshots.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-messaging-and-queue

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 Dec 16, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libpng 1.6.51-r0 CVE-2025-66293 HIGH
libpng-dev 1.6.51-r0 CVE-2025-66293 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: 0

🧹 Nitpick comments (1)
src/Appwrite/Event/Event.php (1)

95-230: Consider applying late static binding consistently across all fluent setters.

The change from self to static improves inheritance support by using late static binding. However, this pattern has been applied to only 7 of the 13 fluent setter methods in the class.

The following methods still return self:

  • setPaused() (line 76)
  • setContext() (line 258)
  • setClass() (line 282)
  • setParam() (line 306)
  • reset() (line 406)
  • from() (line 614)

For consistency and to fully support fluent chaining in subclasses, consider updating the remaining setter methods to also return static. If certain methods should intentionally return self, documenting the rationale would be helpful for future maintainers.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd000c and c912b51.

📒 Files selected for processing (2)
  • src/Appwrite/Event/Event.php (7 hunks)
  • src/Appwrite/Platform/Workers/Messaging.php (1 hunks)
⏰ 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). (4)
  • GitHub Check: Agent
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
src/Appwrite/Platform/Workers/Messaging.php (1)

390-392: LGTM: Lazy initialization pattern correctly implemented.

The lazy initialization of the SMS adapter is appropriate and defers resource creation until actually needed. The existing null-check fallback at line 394 ensures graceful degradation if adapter creation fails.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements two performance and type safety improvements for the Appwrite messaging system. The changes prevent unnecessary SMS adapter initialization in worker processes and improve type inference for method chaining in Event classes.

Key Changes:

  • Lazy initialization of SMS adapter in Messaging worker to avoid creating adapter instances in workers that don't process SMS messages
  • Late static binding for Event class setter methods to return correct subclass types instead of parent Event type

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Appwrite/Platform/Workers/Messaging.php Moved SMS adapter initialization from constructor to lazy initialization in sendInternalSMSMessage method, preventing unnecessary adapter creation when worker handles non-SMS messages
src/Appwrite/Event/Event.php Changed return types from self to static for setter methods (setQueue, setEvent, setProject, setPlatform, setUser, setUserId, setPayload) to enable proper type inference in subclasses through late static binding

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChiragAgg5k ChiragAgg5k force-pushed the refactor-messaging-and-queue branch from c912b51 to c7fd312 Compare December 16, 2025 05:16
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: 0

🧹 Nitpick comments (1)
src/Appwrite/Event/Event.php (1)

76-406: Consider unifying return types for all fluent interface methods.

Several other setter methods (setPaused, setContext, setClass, setParam, reset) still return self rather than static. While the current changes fix the immediate type errors, adopting static consistently across all fluent methods would improve type safety and prevent similar issues in the future.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c912b51 and c7fd312.

📒 Files selected for processing (4)
  • src/Appwrite/Event/Database.php (1 hunks)
  • src/Appwrite/Event/Event.php (7 hunks)
  • src/Appwrite/Event/Messaging.php (0 hunks)
  • src/Appwrite/Platform/Workers/Messaging.php (1 hunks)
💤 Files with no reviewable changes (1)
  • src/Appwrite/Event/Messaging.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Appwrite/Platform/Workers/Messaging.php
🧰 Additional context used
🧬 Code graph analysis (2)
src/Appwrite/Event/Database.php (1)
src/Appwrite/Event/Event.php (1)
  • setProject (142-146)
src/Appwrite/Event/Event.php (1)
src/Appwrite/Event/Database.php (1)
  • setProject (164-178)
⏰ 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: Benchmark
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (2)
src/Appwrite/Event/Database.php (1)

164-178: LGTM! Correct use of late static binding.

The change from self to static enables proper type resolution in method chaining when Database extends Event. This allows subclasses to return their own type rather than the parent type, fixing type-related errors.

src/Appwrite/Event/Event.php (1)

95-230: LGTM! Late static binding correctly implemented.

The changes from self to static return types enable proper type inference for subclasses, addressing the type errors mentioned in the PR objectives. These modifications maintain backward compatibility while improving type safety in inheritance chains.

@github-actions
Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 1,127
  • Requests with 200 status code: 202,923
  • P99 latency: 0.171643088

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,127 1,216
200 202,923 218,851
P99 0.171643088 0.169525184

@abnegate abnegate merged commit e3e7f56 into 1.8.x Dec 16, 2025
72 of 73 checks passed
@abnegate abnegate deleted the refactor-messaging-and-queue branch December 16, 2025 06:25
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.

3 participants