Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muliple subscriptions for same Device #135

Open
jeremyknoepfel opened this issue Jan 19, 2024 · 5 comments
Open

Muliple subscriptions for same Device #135

jeremyknoepfel opened this issue Jan 19, 2024 · 5 comments

Comments

@jeremyknoepfel
Copy link

When a user has subscribed for push it creates an entry in the subscription info. However if his browser gets updated to a newer version a new entry gets added.

This now has the effect, that the following user gets the same push message sent 5 times to his device when using the send_notification_to_user method.

image

@safwanrahman
Copy link
Owner

@jeremyknoepfel Thanks. That is really interesting! I do not know how this happens, maybe chrome changed something? Can you check on Firefox as well?

@jeremyknoepfel
Copy link
Author

@safwanrahman Unfortunately i didn't have time to test it on Firefox. The problem still occurs with Chrome. Isn't it possible to make the combination of auth and browser unique to each user?

@SHxKM
Copy link

SHxKM commented Mar 7, 2024

Isn't there a mechanism to check whether the current browser is subscribed to push events, preventing this situation altogether?

@jeremyknoepfel
Copy link
Author

jeremyknoepfel commented May 1, 2024

@safwanrahman
The issue still exists. I found a fix which has to be executed periodically. Currently I'm running this script every hour with celery:

from django.db.models import Count, Min
    from webpush.models import SubscriptionInfo
    # Step 1: Annotate each WebpushSubscriptionInfo with the minimum id for each group of auth and p256dh.
    duplicates = (
        SubscriptionInfo.objects
        .values('auth', 'p256dh')
        .annotate(min_id=Min('id'), count_id=Count('id'))
        .filter(count_id__gt=1)
    )
    # Step 2: Collect the IDs of the entries with the lowest id in each group.
    min_ids_to_delete = [entry['min_id'] for entry in duplicates]
    # Step 3: Delete these entries.
    SubscriptionInfo.objects.filter(id__in=min_ids_to_delete).delete()

A long term solution for the django-webpush package would be to set the auth&p256dh as unique und update the existing entry instead of creating a new one when the client browser updates.

@4c1dhydr4
Copy link

hi @safwanrahman thank you for this contribution, Are there any plans to introduce a fix to the issue soon?

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

No branches or pull requests

4 participants