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