notifications-timestamp-fix
Some checks failed
Deploy on push / deploy (push) Failing after 6s

This commit is contained in:
2025-08-21 11:27:13 +03:00
parent dc4958e645
commit 9c0a5af67a

View File

@@ -1,4 +1,5 @@
import time import time
from datetime import datetime
from typing import Any from typing import Any
import orjson import orjson
@@ -32,16 +33,21 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[
), ),
) )
if after: 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) q = q.group_by(NotificationSeen.notification, Notification.created_at)
with local_session() as session: with local_session() as session:
# Convert Unix timestamp to datetime for PostgreSQL compatibility
after_datetime = datetime.fromtimestamp(after) if after else None
total = ( total = (
session.query(Notification) session.query(Notification)
.where( .where(
and_( and_(
Notification.action == NotificationAction.CREATE.value, Notification.action == NotificationAction.CREATE.value,
Notification.created_at > after, Notification.created_at > after_datetime,
) )
) )
.count() .count()
@@ -52,7 +58,7 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[
.where( .where(
and_( and_(
Notification.action == NotificationAction.CREATE.value, Notification.action == NotificationAction.CREATE.value,
Notification.created_at > after, Notification.created_at > after_datetime,
not_(Notification.seen), 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") author_id = info.context.get("author", {}).get("id")
if author_id: if author_id:
with local_session() as session: 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: for notification in nnn:
ns = NotificationSeen(notification=notification.id, author=author_id) ns = NotificationSeen(notification=notification.id, author=author_id)
session.add(ns) session.add(ns)
@@ -279,13 +287,16 @@ async def notifications_seen_thread(_: None, info: GraphQLResolveInfo, thread: s
if author_id: if author_id:
[shout_id, reply_to_id] = thread.split(":") [shout_id, reply_to_id] = thread.split(":")
with local_session() as session: 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 # TODO: handle new follower and new shout notifications
new_reaction_notifications = ( new_reaction_notifications = (
session.query(Notification) session.query(Notification)
.where( .where(
Notification.action == "create", Notification.action == "create",
Notification.entity == "reaction", Notification.entity == "reaction",
Notification.created_at > after, Notification.created_at > after_datetime,
) )
.all() .all()
) )
@@ -294,7 +305,7 @@ async def notifications_seen_thread(_: None, info: GraphQLResolveInfo, thread: s
.where( .where(
Notification.action == "delete", Notification.action == "delete",
Notification.entity == "reaction", Notification.entity == "reaction",
Notification.created_at > after, Notification.created_at > after_datetime,
) )
.all() .all()
) )