This commit is contained in:
2022-11-16 10:32:24 +03:00
parent edb68dc0dd
commit 2dd6327edd
6 changed files with 36 additions and 33 deletions

View File

@@ -9,13 +9,13 @@ from orm.user import AuthorFollower
@query.field("searchUsers")
@login_required
async def search_users(_, info, query: str, offset: int = 0, amount: int = 50):
async def search_users(_, info, query: str, limit: int = 50, offset: int = 0):
result = []
# TODO: maybe redis scan?
user = info.context["request"].user
talk_before = await redis.execute("GET", f"/chats_by_user/{user.slug}")
if talk_before:
talk_before = list(json.loads(talk_before))[offset:offset + amount]
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}/users")
if members:
@@ -26,17 +26,17 @@ async def search_users(_, info, query: str, offset: int = 0, amount: int = 50):
result.append(member)
user = info.context["request"].user
more_amount = amount - len(result)
more_amount = limit - len(result)
with local_session() as session:
# followings
result += session.query(AuthorFollower.author).where(AuthorFollower.follower.startswith(query))\
.offset(offset + len(result)).limit(more_amount)
more_amount = amount
more_amount = limit
# followers
result += session.query(AuthorFollower.follower).where(AuthorFollower.author.startswith(query))\
.offset(offset + len(result)).limit(offset + len(result) + amount)
.offset(offset + len(result)).limit(offset + len(result) + limit)
return {
"slugs": list(result),
"error": None