-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
=
committed
Sep 16, 2024
1 parent
7f9fe60
commit 15e45c8
Showing
27 changed files
with
1,565 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
auctions/management/commands/webpush_notifications_deduplicate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Count, Min | ||
from webpush.models import SubscriptionInfo | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Duplicate subscriptions can be created, this removes them. See https://github.com/safwanrahman/django-webpush/issues/135" | ||
|
||
def handle(self, *args, **options): | ||
# 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() |
Oops, something went wrong.