debug-core-conector

This commit is contained in:
Untone 2023-10-13 15:48:53 +03:00
parent 4e078bf978
commit d8c3f80451
2 changed files with 4 additions and 5 deletions

View File

@ -44,7 +44,6 @@ async def load_messages(chat_id: str, limit: int = 5, offset: int = 0, ids=None)
async def load_chats(_, info, limit: int = 50, offset: int = 0): async def load_chats(_, info, limit: int = 50, offset: int = 0):
"""load :limit chats of current user with :offset""" """load :limit chats of current user with :offset"""
author_id = info.context["author_id"] author_id = info.context["author_id"]
print(f"Loading chats for user with id={author_id}")
cids = (await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or [] cids = (await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")) or []
members_online = (await redis.execute("SMEMBERS", "authors-online")) or [] members_online = (await redis.execute("SMEMBERS", "authors-online")) or []
cids = list(cids)[offset:(offset + limit)] cids = list(cids)[offset:(offset + limit)]
@ -53,13 +52,12 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
if len(cids) == 0: if len(cids) == 0:
print(f"[resolvers.load] no chats for user with id={author_id}, create one with Discours (id=2)") print(f"[resolvers.load] no chats for user with id={author_id}, create one with Discours (id=2)")
r = await create_chat(None, info, members=[2]) # member with id = 2 is discours r = await create_chat(None, info, members=[2]) # member with id = 2 is discours
print(f"{r}") print(f"[resolvers.load] created chat: {r}")
cids.append(r["chat"]["id"]) cids.append(r["chat"]["id"])
for cid in cids: for cid in cids:
print(f"Processing chat ID: {cid}")
async with lock: async with lock:
c = await redis.execute("GET", f"chats/{cid}") c = await redis.execute("GET", f"chats/{cid}")
print(f"GET result for chat {cid}: {c}") print(f"[resolvers.load] redis GET by {cid}: {c}")
if c: if c:
c = json.loads(c) c = json.loads(c)
c["messages"] = await load_messages(cid, 5, 0) c["messages"] = await load_messages(cid, 5, 0)
@ -68,7 +66,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
c["members"] = [] c["members"] = []
for member_id in member_ids: for member_id in member_ids:
a = await get_author(member_id) a = await get_author(member_id)
print(f"{a}") print(f"[resolvers.load] author with id={member_id}: {a}")
if a: if a:
c["members"].append( c["members"].append(
{ {

View File

@ -16,6 +16,7 @@ async def get_author(author_id):
try: try:
async with AsyncClient() as client: async with AsyncClient() as client:
response = await client.post(API_BASE, headers=headers, data=gql) response = await client.post(API_BASE, headers=headers, data=gql)
print(f"[services.core] get_author response: {response.status_code} {response.text}")
if response.status_code != 200: if response.status_code != 200:
return None return None
r = response.json() r = response.json()