This commit is contained in:
parent
2658cd323b
commit
2d588c549e
|
@ -4,7 +4,7 @@ import uuid
|
||||||
|
|
||||||
from models.chat import Chat, ChatUpdate
|
from models.chat import Chat, ChatUpdate
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.core import get_all_authors
|
from services.core import cached_authors
|
||||||
from services.presence import notify_chat
|
from services.presence import notify_chat
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.schema import mutation
|
from services.schema import mutation
|
||||||
|
@ -51,7 +51,7 @@ async def update_chat(_, info, chat_new: ChatUpdate):
|
||||||
async def create_chat(_, info, title="", members=None):
|
async def create_chat(_, info, title="", members=None):
|
||||||
members = members or []
|
members = members or []
|
||||||
user_id = info.context["user_id"]
|
user_id = info.context["user_id"]
|
||||||
authors_by_user, authors_by_id = get_all_authors()
|
authors_by_user, authors_by_id = cached_authors
|
||||||
author = authors_by_user[user_id]
|
author = authors_by_user[user_id]
|
||||||
author_id = author["id"]
|
author_id = author["id"]
|
||||||
chat = None
|
chat = None
|
||||||
|
|
|
@ -6,7 +6,7 @@ from models.chat import ChatPayload, Message
|
||||||
from models.member import ChatMember
|
from models.member import ChatMember
|
||||||
from resolvers.chats import create_chat
|
from resolvers.chats import create_chat
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.core import get_all_authors, get_my_followed
|
from services.core import cached_authors, get_my_followed
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
|
|
||||||
|
@ -65,7 +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
|
r = await create_chat(None, info, members=[1]) # member with id = 1 is discours
|
||||||
print(f"[resolvers.load] created chat: {r['chat_id']}")
|
print(f"[resolvers.load] created chat: {r['chat_id']}")
|
||||||
cids.append(r["chat"]["id"])
|
cids.append(r["chat"]["id"])
|
||||||
authors_by_user, authors_by_id = get_all_authors()
|
authors_by_user, authors_by_id = cached_authors
|
||||||
for cid in cids:
|
for cid in cids:
|
||||||
async with lock:
|
async with lock:
|
||||||
chat_str: str = await redis.execute("GET", f"chats/{cid}")
|
chat_str: str = await redis.execute("GET", f"chats/{cid}")
|
||||||
|
@ -119,7 +119,7 @@ async def load_recipients(_, _info, limit=50, offset=0):
|
||||||
r = []
|
r = []
|
||||||
my_followings: List[ChatMember] = get_my_followed()
|
my_followings: List[ChatMember] = get_my_followed()
|
||||||
if len(my_followings) < limit:
|
if len(my_followings) < limit:
|
||||||
authors_by_user, authors_by_id = get_all_authors()
|
authors_by_user, authors_by_id = cached_authors
|
||||||
my_followings = my_followings + list(authors_by_id.values())[offset : limit - len(my_followings)]
|
my_followings = my_followings + list(authors_by_id.values())[offset : limit - len(my_followings)]
|
||||||
my_followings = list(set(my_followings))
|
my_followings = list(set(my_followings))
|
||||||
for a in my_followings:
|
for a in my_followings:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
from resolvers.load import load_messages
|
from resolvers.load import load_messages
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.core import get_all_authors
|
from services.core import cached_authors
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
|
||||||
|
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
|
|
||||||
authors_by_user, authors_by_id = get_all_authors()
|
authors_by_user, authors_by_id = cached_authors
|
||||||
|
|
||||||
existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{author_id}")
|
existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{author_id}")
|
||||||
if existed_chats:
|
if existed_chats:
|
||||||
|
|
|
@ -62,6 +62,7 @@ def login_required(f):
|
||||||
context["user_id"] = user_id
|
context["user_id"] = user_id
|
||||||
if not cached_authors:
|
if not cached_authors:
|
||||||
get_all_authors()
|
get_all_authors()
|
||||||
|
if cached_authors:
|
||||||
authors_by_user, authors_by_id = cached_authors
|
authors_by_user, authors_by_id = cached_authors
|
||||||
author = authors_by_user.get(user_id)
|
author = authors_by_user.get(user_id)
|
||||||
if author and "id" in author:
|
if author and "id" in author:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user