cached-request
All checks were successful
deploy / deploy (push) Successful in 1m3s

This commit is contained in:
2023-12-19 18:58:26 +03:00
parent b141c26e80
commit 6c7f269206
6 changed files with 40 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ import uuid
from models.chat import Chat, ChatUpdate
from services.auth import login_required
from services.core import authors_by_user
from services.core import get_all_authors
from services.presence import notify_chat
from services.rediscache import redis
from services.schema import mutation
@@ -53,6 +53,7 @@ async def create_chat(_, info, title="", members=None):
print("create_chat members: %r" % members)
print("create_chat context: %r" % info.context)
user_id = info.context["user_id"]
authors_by_user, authors_by_id = get_all_authors()
author = authors_by_user[user_id]
author_id = author["id"]
chat = None

View File

@@ -6,7 +6,7 @@ from models.chat import ChatPayload, Message
from models.member import ChatMember
from resolvers.chats import create_chat
from services.auth import login_required
from services.core import authors_by_id, get_my_followed
from services.core import get_all_authors, get_my_followed
from services.rediscache import redis
from services.schema import query
@@ -65,6 +65,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
r = await create_chat(None, info, members=[1]) # member with id = 1 is discours
print(f"[resolvers.load] created chat: {r['chat_id']}")
cids.append(r["chat"]["id"])
authors_by_user, authors_by_id = get_all_authors()
for cid in cids:
async with lock:
chat_str: str = await redis.execute("GET", f"chats/{cid}")
@@ -118,6 +119,7 @@ async def load_recipients(_, _info, limit=50, offset=0):
r = []
my_followings: List[ChatMember] = get_my_followed()
if len(my_followings) < limit:
authors_by_user, authors_by_id = get_all_authors()
my_followings = my_followings + list(authors_by_id.values())[offset : limit - len(my_followings)]
my_followings = list(set(my_followings))
for a in my_followings:

View File

@@ -4,7 +4,7 @@ from typing import Any, Dict, List, Union
from resolvers.load import load_messages
from services.auth import login_required
from services.core import authors_by_id
from services.core import get_all_authors
from services.rediscache import redis
from services.schema import query
@@ -18,6 +18,8 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
author_id = info.context["author_id"]
authors_by_user, authors_by_id = get_all_authors()
existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{author_id}")
if existed_chats:
for chat_id in list(json.loads(existed_chats))[offset : (offset + limit)]: