precommit
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
from sqlalchemy.sql import not_
|
||||
from services.db import local_session
|
||||
from resolvers.model import (
|
||||
@@ -10,10 +9,10 @@ from resolvers.model import (
|
||||
)
|
||||
from orm.notification import NotificationAction, NotificationEntity, NotificationSeen, Notification
|
||||
from typing import Dict, List
|
||||
import time, json
|
||||
import time
|
||||
import json
|
||||
import strawberry
|
||||
from sqlalchemy.orm import aliased
|
||||
from sqlalchemy.sql.expression import or_
|
||||
from sqlalchemy import select, and_
|
||||
import logging
|
||||
|
||||
@@ -62,14 +61,22 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||
notifications_by_thread: Dict[str, List[Notification]] = {}
|
||||
groups_by_thread: Dict[str, NotificationGroup] = {}
|
||||
with local_session() as session:
|
||||
total = session.query(Notification).filter(and_(Notification.action == NotificationAction.CREATE.value, Notification.created_at > after)).count()
|
||||
unread = session.query(Notification).filter(
|
||||
and_(
|
||||
Notification.action == NotificationAction.CREATE.value,
|
||||
Notification.created_at > after,
|
||||
not_(Notification.seen)
|
||||
total = (
|
||||
session.query(Notification)
|
||||
.filter(and_(Notification.action == NotificationAction.CREATE.value, Notification.created_at > after))
|
||||
.count()
|
||||
)
|
||||
unread = (
|
||||
session.query(Notification)
|
||||
.filter(
|
||||
and_(
|
||||
Notification.action == NotificationAction.CREATE.value,
|
||||
Notification.created_at > after,
|
||||
not_(Notification.seen),
|
||||
)
|
||||
)
|
||||
).count()
|
||||
.count()
|
||||
)
|
||||
notifications_result = session.execute(query)
|
||||
for n, seen in notifications_result:
|
||||
thread_id = ""
|
||||
@@ -87,7 +94,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||
updated_at=shout.created_at,
|
||||
reactions=[],
|
||||
action="create",
|
||||
seen=author_id in n.seen
|
||||
seen=author_id in n.seen,
|
||||
)
|
||||
# store group in result
|
||||
groups_by_thread[thread_id] = group
|
||||
@@ -140,7 +147,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||
authors=[
|
||||
reaction.created_by,
|
||||
],
|
||||
seen=author_id in n.seen
|
||||
seen=author_id in n.seen,
|
||||
)
|
||||
# store group in result
|
||||
groups_by_thread[thread_id] = group
|
||||
@@ -153,16 +160,18 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||
thread_id = "followers"
|
||||
follower: NotificationAuthor = payload
|
||||
group = groups_by_thread.get(thread_id) or NotificationGroup(
|
||||
id=thread_id,
|
||||
authors=[follower],
|
||||
updated_at=int(time.time()),
|
||||
shout=None,
|
||||
reactions=[],
|
||||
entity="follower",
|
||||
action="follow",
|
||||
seen=author_id in n.seen
|
||||
)
|
||||
group.authors = [follower, ]
|
||||
id=thread_id,
|
||||
authors=[follower],
|
||||
updated_at=int(time.time()),
|
||||
shout=None,
|
||||
reactions=[],
|
||||
entity="follower",
|
||||
action="follow",
|
||||
seen=author_id in n.seen,
|
||||
)
|
||||
group.authors = [
|
||||
follower,
|
||||
]
|
||||
group.updated_at = int(time.time())
|
||||
# store group in result
|
||||
groups_by_thread[thread_id] = group
|
||||
|
Reference in New Issue
Block a user