This commit is contained in:
parent
37b3391660
commit
e3cf4a05ee
|
@ -4,7 +4,7 @@ from typing import Dict, Union, List, Any
|
|||
|
||||
from resolvers.load import load_messages
|
||||
from services.auth import login_required
|
||||
from services.core import get_network
|
||||
from services.core import get_network, get_author
|
||||
from services.rediscache import redis
|
||||
from services.schema import query
|
||||
|
||||
|
@ -17,17 +17,15 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
|
|||
# TODO: maybe redis scan?
|
||||
|
||||
author_id = info.context["author_id"]
|
||||
talk_before = await redis.execute("GET", f"/chats_by_author/{author_id}")
|
||||
if talk_before:
|
||||
talk_before = list(json.loads(talk_before))[offset : (offset + limit)]
|
||||
for chat_id in talk_before:
|
||||
members = await redis.execute("GET", f"/chats/{chat_id}/members")
|
||||
if members:
|
||||
members = list(json.loads(members))
|
||||
for member in members:
|
||||
if member.startswith(text):
|
||||
if member not in result:
|
||||
result.append(member)
|
||||
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)]:
|
||||
members_ids = await redis.execute("GET", f"/chats/{chat_id}/members")
|
||||
for member_id in members_ids:
|
||||
author = await get_author(member_id)
|
||||
if author["name"].startswith(text):
|
||||
if author not in result:
|
||||
result.append(author)
|
||||
|
||||
more_amount = limit - len(result)
|
||||
if more_amount > 0:
|
||||
|
|
|
@ -16,7 +16,7 @@ async def get_author(author_id):
|
|||
}
|
||||
}""",
|
||||
"operation": "GetAuthorById",
|
||||
"variables": {"author_id": author_id},
|
||||
"variables": {"author_id": int(author_id)},
|
||||
}
|
||||
async with AsyncClient() as client:
|
||||
response = await client.post(API_BASE, headers=headers, json=gql)
|
||||
|
|
Loading…
Reference in New Issue
Block a user