perf: reuse authorized chat snapshot when reading history
This commit is contained in:
+2
-2
@@ -268,13 +268,13 @@ async def send(request: Request, chat_id: str):
|
||||
async def history(request: Request, chat_id: str):
|
||||
user = await actor(request)
|
||||
cid = parse_uuid(chat_id)
|
||||
await run_io(service(request).get_chat, actor_id=user.id, chat_id=cid)
|
||||
chat = await run_io(service(request).get_chat, actor_id=user.id, chat_id=cid)
|
||||
limit, cursor = pagination(request)
|
||||
return response(
|
||||
await run_io(
|
||||
service(request).history,
|
||||
actor_id=user.id,
|
||||
chat_id=cid,
|
||||
chat=chat,
|
||||
limit=limit,
|
||||
cursor=cursor,
|
||||
)
|
||||
|
||||
+5
-3
@@ -7,7 +7,7 @@ from uuid import UUID, uuid4
|
||||
|
||||
from src.cursor import decode_cursor, encode_cursor
|
||||
from src.domain import Chat, Message, Record, User, order_key, utcnow
|
||||
from src.errors import DomainError, invalid
|
||||
from src.errors import DomainError, invalid, not_found
|
||||
from src.password import Passwords
|
||||
from src.repository import PostgresRepository
|
||||
|
||||
@@ -158,9 +158,11 @@ class MessengerService:
|
||||
return page(rows=rows, limit=limit, scope=scope)
|
||||
|
||||
def history(
|
||||
self, *, actor_id: UUID, chat_id: UUID, limit: int, cursor: str | None
|
||||
self, *, actor_id: UUID, chat: Chat, limit: int, cursor: str | None
|
||||
) -> dict:
|
||||
self.get_chat(actor_id=actor_id, chat_id=chat_id)
|
||||
if actor_id not in chat.member_ids:
|
||||
raise not_found()
|
||||
chat_id = chat.id
|
||||
scope = f"messages:{chat_id}"
|
||||
after = decode_cursor(value=cursor, scope=scope)
|
||||
rows = self.repository.list_messages(
|
||||
|
||||
Reference in New Issue
Block a user