unmiddlewared
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
|
||||
from services.core import get_author
|
||||
from services.db import local_session
|
||||
from services.redis import redis
|
||||
from resolvers import query
|
||||
from orm.author import Author
|
||||
from services.auth import login_required
|
||||
from .chats import create_chat
|
||||
from .unread import get_unread_counter
|
||||
@@ -63,7 +63,7 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
|
||||
member_ids = c["members"].copy()
|
||||
c["members"] = []
|
||||
for member_id in member_ids:
|
||||
a = session.query(Author).where(Author.id == member_id).first()
|
||||
a = await get_author(member_id)
|
||||
if a:
|
||||
c["members"].append(
|
||||
{
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import json
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from services.auth import login_required
|
||||
from services.core import get_network
|
||||
from services.redis import redis
|
||||
from resolvers import query
|
||||
from services.db import local_session
|
||||
from orm.author import AuthorFollower, Author
|
||||
from resolvers.load import load_messages
|
||||
|
||||
|
||||
@@ -13,8 +12,8 @@ from resolvers.load import load_messages
|
||||
async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0):
|
||||
result = []
|
||||
# TODO: maybe redis scan?
|
||||
author = info.context["author"]
|
||||
talk_before = await redis.execute("GET", f"/chats_by_author/{author.id}")
|
||||
author_id = info.context["author_id"]
|
||||
talk_before = await redis.execute("GET", f"/chats_by_author/{author_id}")
|
||||
if talk_before:
|
||||
talk_before = list(json.loads(talk_before))[offset : (offset + limit)]
|
||||
for chat_id in talk_before:
|
||||
@@ -27,25 +26,8 @@ async def search_recipients(_, info, text: str, limit: int = 50, offset: int = 0
|
||||
result.append(member)
|
||||
|
||||
more_amount = limit - len(result)
|
||||
|
||||
with local_session() as session:
|
||||
# followings
|
||||
result += (
|
||||
session.query(AuthorFollower.author)
|
||||
.join(Author, Author.id == AuthorFollower.follower)
|
||||
.where(Author.slug.startswith(text))
|
||||
.offset(offset + len(result))
|
||||
.limit(more_amount)
|
||||
)
|
||||
|
||||
# followers
|
||||
result += (
|
||||
session.query(AuthorFollower.follower)
|
||||
.join(Author, Author.id == AuthorFollower.author)
|
||||
.where(Author.slug.startswith(text))
|
||||
.offset(offset + len(result))
|
||||
.limit(offset + len(result) + limit)
|
||||
)
|
||||
if more_amount > 0:
|
||||
result += await get_network(author_id, more_amount)
|
||||
return {"members": list(result), "error": None}
|
||||
|
||||
|
||||
@@ -84,7 +66,7 @@ async def search_in_chats(_, info, by, limit, offset):
|
||||
)
|
||||
|
||||
messages_set.union(set(mmm))
|
||||
|
||||
messages_sorted = list(messages_set).sort()
|
||||
return {"messages": messages_sorted, "error": None}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user