signIn/getSession optimization (#95)

Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com>
This commit is contained in:
Ilya Y
2023-10-19 17:54:38 +03:00
committed by GitHub
parent 4c6747ab35
commit da8ee9b9c3
4 changed files with 41 additions and 60 deletions

View File

@@ -1,5 +1,4 @@
from base.redis import redis
import json
async def get_unread_counter(chat_id: str, user_id: int):
@@ -9,14 +8,3 @@ async def get_unread_counter(chat_id: str, user_id: int):
return unread
except Exception:
return 0
async def get_total_unread_counter(user_id: int):
chats = await redis.execute("GET", f"chats_by_user/{str(user_id)}")
unread = 0
if chats:
chats = json.loads(chats)
for chat_id in chats:
n = await get_unread_counter(chat_id.decode('utf-8'), user_id)
unread += n
return unread