logs-redis-typings-fix

This commit is contained in:
2024-01-24 00:13:14 +03:00
parent 9b03e625f4
commit 8901ded662
7 changed files with 67 additions and 74 deletions

View File

@@ -21,7 +21,7 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
existed_chats = await redis.execute("SMEMBERS", f"/chats_by_author/{author_id}")
if isinstance(existed_chats, set):
chats_list = list(existed_chats)
for chat_id in chats_list[offset: (offset + limit)]:
for chat_id in chats_list[offset : (offset + limit)]:
members_ids = await redis.execute("SMEMBERS", f"/chats/{chat_id}/members")
if isinstance(members_ids, set):
for member_id in members_ids:
@@ -36,7 +36,6 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
return {"members": list(result), "error": None}
@query.field("search_messages")
@login_required
async def search_messages(
@@ -45,8 +44,7 @@ async def search_messages(
messages_set = set([])
author_id = info.context["author_id"]
lookup_chats = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}")
if isinstance(lookup_chats, list):
lookup_chats = set(lookup_chats)
if isinstance(lookup_chats, set):
# pre-filter lookup chats
by_member = by.get("author")
@@ -59,7 +57,6 @@ async def search_messages(
# load the messages from lookup chats
for c in lookup_chats:
chat_id = c.decode()
mmm = await load_messages(chat_id, limit, offset)
filter_method = None
if by_member:
filter_method = lambda mx: mx and mx["created_by"] == by_member
@@ -70,7 +67,9 @@ async def search_messages(
if days_ago:
filter_method = lambda mx: mx and (int(time.time()) - mx["created_by"] < days_ago * 24 * 60 * 60)
if filter_method:
mmm = list(filter(filter_method, mmm))
messages_set |= set(mmm)
mmm = await load_messages(chat_id, limit, offset)
if isinstance(mmm, list):
mmm = list(filter(filter_method, mmm))
messages_set |= set(mmm)
return {"messages": sorted(list(messages_set)), "error": None}