precommit

This commit is contained in:
2024-02-04 07:58:44 +03:00
parent 537b89dbaf
commit b98da839ed
10 changed files with 64 additions and 31 deletions

View File

@@ -1,11 +1,11 @@
from orm.notification import Notification, NotificationAction, NotificationEntity
from orm.notification import Notification
from resolvers.model import NotificationReaction, NotificationAuthor, NotificationShout
from services.db import local_session
from services.rediscache import redis
import asyncio
import logging
logger = logging.getLogger(f"[listener.listen_task] ")
logger = logging.getLogger("[listener.listen_task] ")
logger.setLevel(logging.DEBUG)

View File

@@ -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

View File

@@ -1,4 +1,3 @@
import strawberry
from strawberry.schema.config import StrawberryConfig

View File

@@ -46,7 +46,7 @@ class Mutation:
ns = NotificationSeen(notification=n.id, viewer=author_id)
session.add(ns)
session.commit()
except SQLAlchemyError as e:
except SQLAlchemyError:
session.rollback()
except Exception as e:
print(e)