fixes
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user