This commit is contained in:
@@ -78,9 +78,7 @@ class NotificationDocument(BaseModel):
|
|||||||
class NotificationBackend(Protocol):
|
class NotificationBackend(Protocol):
|
||||||
"""Backend-agnostic interface for notification storage."""
|
"""Backend-agnostic interface for notification storage."""
|
||||||
|
|
||||||
async def get_recent_notifications(
|
async def get_recent_notifications(self, phone_number: str) -> list[Notification]:
|
||||||
self, phone_number: str
|
|
||||||
) -> list[Notification]:
|
|
||||||
"""Return recent notifications for *phone_number*."""
|
"""Return recent notifications for *phone_number*."""
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -113,9 +111,7 @@ class FirestoreNotificationBackend:
|
|||||||
self._max_to_notify = max_to_notify
|
self._max_to_notify = max_to_notify
|
||||||
self._window_hours = window_hours
|
self._window_hours = window_hours
|
||||||
|
|
||||||
async def get_recent_notifications(
|
async def get_recent_notifications(self, phone_number: str) -> list[Notification]:
|
||||||
self, phone_number: str
|
|
||||||
) -> list[Notification]:
|
|
||||||
"""Get recent notifications for a user.
|
"""Get recent notifications for a user.
|
||||||
|
|
||||||
Retrieves notifications created within the configured time window,
|
Retrieves notifications created within the configured time window,
|
||||||
@@ -148,9 +144,7 @@ class FirestoreNotificationBackend:
|
|||||||
cutoff = time.time() - (self._window_hours * 3600)
|
cutoff = time.time() - (self._window_hours * 3600)
|
||||||
|
|
||||||
parsed = [
|
parsed = [
|
||||||
n
|
n for n in document.notificaciones if n.timestamp_creacion >= cutoff
|
||||||
for n in document.notificaciones
|
|
||||||
if n.timestamp_creacion >= cutoff
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if not parsed:
|
if not parsed:
|
||||||
@@ -212,9 +206,7 @@ class RedisNotificationBackend:
|
|||||||
self._max_to_notify = max_to_notify
|
self._max_to_notify = max_to_notify
|
||||||
self._window_hours = window_hours
|
self._window_hours = window_hours
|
||||||
|
|
||||||
async def get_recent_notifications(
|
async def get_recent_notifications(self, phone_number: str) -> list[Notification]:
|
||||||
self, phone_number: str
|
|
||||||
) -> list[Notification]:
|
|
||||||
"""Get recent notifications for a user from Redis.
|
"""Get recent notifications for a user from Redis.
|
||||||
|
|
||||||
Reads from the ``notification:{phone}`` key, parses the JSON
|
Reads from the ``notification:{phone}`` key, parses the JSON
|
||||||
@@ -246,9 +238,7 @@ class RedisNotificationBackend:
|
|||||||
cutoff = time.time() - (self._window_hours * 3600)
|
cutoff = time.time() - (self._window_hours * 3600)
|
||||||
|
|
||||||
parsed = [
|
parsed = [
|
||||||
n
|
n for n in document.notificaciones if n.timestamp_creacion >= cutoff
|
||||||
for n in document.notificaciones
|
|
||||||
if n.timestamp_creacion >= cutoff
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if not parsed:
|
if not parsed:
|
||||||
|
|||||||
Reference in New Issue
Block a user