From cd2e4a08b39d73b953a2d5254146a38b8ae9b1a1 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 14 Nov 2023 21:31:02 +0300 Subject: [PATCH] format+fix-2 --- resolvers/search.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/resolvers/search.py b/resolvers/search.py index 750d392..cd3901d 100644 --- a/resolvers/search.py +++ b/resolvers/search.py @@ -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_all_authors from services.rediscache import redis from services.schema import query @@ -18,18 +18,21 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0 author_id = info.context["author_id"] existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{author_id}") + authors = await get_all_authors() + members = {a["id"]: a for a in authors} 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: - for author in (await get_network(member_id), 1): + author = members.get(member_id) + if author: if author["name"].startswith(text): if author not in result: result.append(author) more_amount = limit - len(result) if more_amount > 0: - result += await get_network(author_id, more_amount) + result += authors[0:more_amount] return {"members": list(result), "error": None}