From 866f89aea49e399d5b831a1ad7df363a1317682e Mon Sep 17 00:00:00 2001 From: Egor Date: Tue, 27 Jan 2026 15:15:24 +0300 Subject: [PATCH] Update notification.py --- app/database/crud/notification.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/database/crud/notification.py b/app/database/crud/notification.py index ef680598..eb26ebdc 100644 --- a/app/database/crud/notification.py +++ b/app/database/crud/notification.py @@ -17,14 +17,16 @@ async def notification_sent( days_before: int | None = None, ) -> bool: result = await db.execute( - select(SentNotification).where( + select(SentNotification) + .where( SentNotification.user_id == user_id, SentNotification.subscription_id == subscription_id, SentNotification.notification_type == notification_type, SentNotification.days_before == days_before, ) + .limit(1) ) - return result.scalar_one_or_none() is not None + return result.scalars().first() is not None async def record_notification( @@ -34,6 +36,9 @@ async def record_notification( notification_type: str, days_before: int | None = None, ) -> None: + already_exists = await notification_sent(db, user_id, subscription_id, notification_type, days_before) + if already_exists: + return notification = SentNotification( user_id=user_id, subscription_id=subscription_id,