Skip to content

feat: add sync_users_tokens_to_raven_cloud to daily maintenance schedule#2076

Merged
nikkothari22 merged 1 commit intodevelopfrom
add-sync-push-tokens-to-daily-maintenance
Mar 14, 2026
Merged

feat: add sync_users_tokens_to_raven_cloud to daily maintenance schedule#2076
nikkothari22 merged 1 commit intodevelopfrom
add-sync-push-tokens-to-daily-maintenance

Conversation

@prathameshkurunkar7
Copy link
Copy Markdown
Member

@prathameshkurunkar7 prathameshkurunkar7 commented Mar 14, 2026

Extension of #2075

Fixed multiple issues which I found with the current notification system. Created fixes on both Raven as well as Raven Cloud(RC). Had to iterate and test fast hence could not write individual PR descriptions. This closes #2036 and potentially other issues that might not have been reported but might be present. But this is just a small gist of the problems I found with the current working and the fixes -

On Raven -

  1. unsubscribed api was performing frappe.db.delete which did not run the document lifecycle of Raven Push Tokens which consisted of on_trash. The on_trash called the delete API on RC. This lead to incorrect/stale tokens being present on RC even when they were removed from Raven. This might be causing duplicate notifications on some devices as well because the tokens might still be valid.
  2. The Sync Data button was not having any error or loading states. Fixed that.
  3. sync_users_tokens_to_raven_cloud splits all tokens into flat chunks of 10. If a single user's tokens span two chunks, the server-side per-user sync deletes the tokens from the first chunk when processing the second — resulting in missing tokens.
    Solution was to - Group tokens by user before chunking, ensuring all tokens for a given user are always sent in the same API call. This is done after fixing the import_user_tokens call on RC.

On RC -

  1. The main problem was with import_user_tokens which only appended the tokens and we did not have a "SYNC" between RC and Raven. Ideally RC should only consist tokens which are present on Raven client. Had to modify the logic for deleting stale/duplicate tokens on RC and keeping only the correct ones considering that Raven Client is the source of truth.
  2. Added unique_constraint on RC Site User Token doctype on fcm_token and user_id so that there are no future cases of duplicate pairs. Wrote a patch for that as well. Fortunately didn't have many records like such hence was very easy to implement this.

What this PR does?

It basically, adds the same sync_users_tokens_to_raven_cloud in a scheduled job. It will ensure that everyday we have mirror image of RC and raven.

@prathameshkurunkar7 prathameshkurunkar7 marked this pull request as ready for review March 14, 2026 16:30
@nikkothari22 nikkothari22 merged commit 03f8722 into develop Mar 14, 2026
2 checks passed
@nikkothari22 nikkothari22 deleted the add-sync-push-tokens-to-daily-maintenance branch March 14, 2026 17:12
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.

PWA receives duplicate notifications

2 participants