From 145bf5aef90e65a8d01cf701ae4cf0f37016c075 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Mon, 29 Dec 2025 21:40:14 +0800 Subject: ignore if sub already exist in db --- backend/notif.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/notif.py b/backend/notif.py index 59c6ec1..d2e1f2e 100644 --- a/backend/notif.py +++ b/backend/notif.py @@ -25,6 +25,12 @@ CREATE TABLE IF NOT EXISTS subscriptions ( # --- subscribe def subscribe(data: PushSubscriptionData): + cursor.execute("SELECT * FROM subscriptions WHERE endpoint = ?", (data.endpoint,)) + row = cursor.fetchall() + + if len(row) > 0: + return data.endpoint + cursor.execute(""" INSERT INTO subscriptions (endpoint, keys_p256dh, keys_auth) VALUES (?, ?, ?)""", (data.endpoint, data.keys["p256dh"], data.keys["auth"])) -- cgit v1.2.3