From 9c0a5af67a1d9bdf4f7556b94899c113a0c2c9d4 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 21 Aug 2025 11:27:13 +0300 Subject: [PATCH] notifications-timestamp-fix --- resolvers/notifier.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/resolvers/notifier.py b/resolvers/notifier.py index 2a61a40e..5d0ce244 100644 --- a/resolvers/notifier.py +++ b/resolvers/notifier.py @@ -1,4 +1,5 @@ import time +from datetime import datetime from typing import Any import orjson @@ -32,16 +33,21 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[ ), ) if after: - q = q.where(Notification.created_at > after) + # Convert Unix timestamp to datetime for PostgreSQL compatibility + after_datetime = datetime.fromtimestamp(after) + q = q.where(Notification.created_at > after_datetime) q = q.group_by(NotificationSeen.notification, Notification.created_at) with local_session() as session: + # Convert Unix timestamp to datetime for PostgreSQL compatibility + after_datetime = datetime.fromtimestamp(after) if after else None + total = ( session.query(Notification) .where( and_( Notification.action == NotificationAction.CREATE.value, - Notification.created_at > after, + Notification.created_at > after_datetime, ) ) .count() @@ -52,7 +58,7 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[ .where( and_( Notification.action == NotificationAction.CREATE.value, - Notification.created_at > after, + Notification.created_at > after_datetime, not_(Notification.seen), ) ) @@ -260,7 +266,9 @@ async def notifications_seen_after(_: None, info: GraphQLResolveInfo, after: int author_id = info.context.get("author", {}).get("id") if author_id: with local_session() as session: - nnn = session.query(Notification).where(and_(Notification.created_at > after)).all() + # Convert Unix timestamp to datetime for PostgreSQL compatibility + after_datetime = datetime.fromtimestamp(after) if after else None + nnn = session.query(Notification).where(and_(Notification.created_at > after_datetime)).all() for notification in nnn: ns = NotificationSeen(notification=notification.id, author=author_id) session.add(ns) @@ -279,13 +287,16 @@ async def notifications_seen_thread(_: None, info: GraphQLResolveInfo, thread: s if author_id: [shout_id, reply_to_id] = thread.split(":") with local_session() as session: + # Convert Unix timestamp to datetime for PostgreSQL compatibility + after_datetime = datetime.fromtimestamp(after) if after else None + # TODO: handle new follower and new shout notifications new_reaction_notifications = ( session.query(Notification) .where( Notification.action == "create", Notification.entity == "reaction", - Notification.created_at > after, + Notification.created_at > after_datetime, ) .all() ) @@ -294,7 +305,7 @@ async def notifications_seen_thread(_: None, info: GraphQLResolveInfo, thread: s .where( Notification.action == "delete", Notification.entity == "reaction", - Notification.created_at > after, + Notification.created_at > after_datetime, ) .all() )