perf: reuse authorized chat snapshot when reading history
This commit is contained in:
+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