Skip to content

Conversation

@fulleni
Copy link
Member

@fulleni fulleni commented Nov 22, 2025

Status

READY

Description

This pull request introduces a significant enhancement to the push notification system by implementing server-side cleanup of invalid device tokens. This new feature ensures that the system remains efficient and reliable by automatically identifying and removing tokens that are no longer valid (e.g., due to app uninstalls), thereby preventing notifications from being sent to non-existent or inactive devices. The changes involve modifying the push notification clients to report detailed send results and integrating a cleanup mechanism into the core notification service.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

… method return types

- Introduce PushNotificationResult class to encapsulate the result of bulk push notification send operations
- Update sendNotification and sendBulkNotifications methods to return PushNotificationResult instead of void
- These changes allow for better error handling and cleanup of invalid device tokens
… result handling

- Refactor sendNotification and sendBulkNotifications to return PushNotificationResult
- Enhance _sendBatch to provide detailed success/failure information
- Log invalid tokens at info level for cleanup purposes
- Reduce log spam by downgrading some log levels
- Simplify error handling and reporting
… results

- Update sendNotification and sendBulkNotifications to return PushNotificationResult
- Implement logic to handle failed notifications within batches
- Process OneSignal API response to identify invalid player IDs
- Refactor _sendBatch to return detailed result of the send operation
- Improve
…ing device tokens

This commit improves the performance of the push notification dispatch process
by grouping device tokens by user ID before sending notifications. This change
avoids iterating through all devices for each user, which reduces the time
complexity from O(N^2) to O(N), significantly speeding up the dispatch process.
…ling

- Refactor error handling logic for better clarity and consistency
- Add detailed comments to explain error handling decisions
- Introduce nuanced error handling for different exception types:
  - Treat NotFoundException as a permanent failure and mark token for cleanup
  - Log other HTTP errors as severe but do not mark for deletion
- Improve log messages with more specific information and context
- Add a new bullet point describing the notification engine's ability to automatically detect and prune invalid device tokens
- This feature ensures long-term reliability and efficient notification delivery
@gemini-code-assist
Copy link

Summary of Changes

Hello @fulleni, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the push notification system by implementing server-side cleanup of invalid device tokens. This new feature ensures that the system remains efficient and reliable by automatically identifying and removing tokens that are no longer valid (e.g., due to app uninstalls), thereby preventing notifications from being sent to non-existent or inactive devices. The changes involve modifying the push notification clients to report detailed send results and integrating a cleanup mechanism into the core notification service.

Highlights

  • Invalid Token Cleanup: Implemented server-side logic to automatically detect and remove invalid or expired push notification tokens from the database.
  • Enhanced Notification Reliability: Modified push notification clients (Firebase and OneSignal) to return detailed results, distinguishing between successfully sent and failed tokens.
  • Service Integration: Integrated the token cleanup process into the main push notification service, ensuring that invalid tokens are asynchronously removed after each send operation.
  • Documentation Update: Updated the README.md to reflect the new "Intelligent, Self-Healing Delivery" capability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust self-healing mechanism for push notifications by cleaning up invalid device tokens. The changes are well-structured, introducing a PushNotificationResult to propagate failure information from notification clients up to the service layer, which then triggers a cleanup process. The refactoring of FirebasePushNotificationClient and OneSignalPushNotificationClient to return this result is a key part of the implementation. Additionally, a performance improvement has been made in DefaultPushNotificationService by pre-grouping device tokens. My feedback includes suggestions to improve error handling consistency, code conciseness, and performance in the cleanup process.

…deletion process

- Use `putIfAbsent` for concise and efficient population of userDeviceTokensMap
- Replace sequential device deletion with parallel deletion using `Future.wait` for improved performance
@fulleni fulleni merged commit b7557ef into main Nov 22, 2025
1 check failed
@fulleni fulleni deleted the feat/Implement-Server-Side-Push-Token-Cleanup branch November 22, 2025 08:11
@github-project-automation github-project-automation bot moved this from Backlog to Done in Flutter News App Project Nov 22, 2025
@fulleni fulleni restored the feat/Implement-Server-Side-Push-Token-Cleanup branch November 22, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants