precached-authors-fix
Some checks are pending
deploy / deploy (push) Waiting to run

This commit is contained in:
2023-12-19 11:25:06 +03:00
parent b2040099a8
commit c3a6ecd3ae
4 changed files with 43 additions and 48 deletions

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 get_all_authors, get_my_followed
from services.core import authors_by_id, get_my_followed
from services.rediscache import redis
from services.schema import query
@@ -65,8 +65,6 @@ 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"])
all_authors: List[ChatMember] = await get_all_authors()
authors = {a["id"]: a for a in all_authors}
for cid in cids:
async with lock:
chat_str: str = await redis.execute("GET", f"chats/{cid}")
@@ -78,7 +76,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni
member_ids = c["members"].copy()
c["members"] = []
for member_id in member_ids:
a = authors.get(member_id)
a = authors_by_id.get(member_id)
if a:
a["online"] = a.get("id") in members_online
c["members"].append(a)
@@ -118,14 +116,13 @@ async def load_recipients(_, _info, limit=50, offset=0):
"""load possible chat participants"""
onliners: List[int] = (await redis.execute("SMEMBERS", "authors-online")) or []
r = []
all_authors: List[ChatMember] = await get_all_authors(limit, offset)
my_followings: List[ChatMember] = await get_my_followed()
if all_authors:
if len(my_followings) < limit:
my_followings = my_followings + list(all_authors)[offset : limit - len(my_followings)]
for a in my_followings:
a["online"] = bool(a["id"] in list(onliners))
r.append(a)
if len(my_followings) < limit:
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:
a["online"] = bool(a["id"] in list(onliners))
r.append(a)
# NOTE: maybe sort members here