forked from mtusi2026/mtusi2026lab2
chore: carry over lab 1 solution into lab 2 skeleton
Copy the committed lab 1 sources as-is: src/, student-tests/, bench/, Dockerfile, docker-compose.yml, pyproject.toml, uv.lock, .python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/, openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays in the lab 1 repository. Merge the new skeleton files with own sections: Makefile (lab 2 targets plus own run, docker, bench and common targets), .gitignore, .dockerignore and .env.example. Rename the image to mtusi-messenger:lab2 and point AGENTS.md at lab 2. The application is still the in-memory lab 1 implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import bisect
|
||||
from uuid import UUID
|
||||
|
||||
from src.infra.memory import MemoryStore
|
||||
from src.schemas import dataclasses
|
||||
from src.utils.cursor import CursorKey
|
||||
|
||||
|
||||
def _message_key(message: dataclasses.MessageFullDTO) -> CursorKey:
|
||||
return (message.created_at, message.id)
|
||||
|
||||
|
||||
async def insert_message(
|
||||
store: MemoryStore,
|
||||
*,
|
||||
message: dataclasses.MessageFullDTO,
|
||||
) -> dataclasses.MessageFullDTO:
|
||||
bisect.insort(
|
||||
store.messages_by_chat[message.chat_id],
|
||||
message,
|
||||
key=_message_key,
|
||||
)
|
||||
return message
|
||||
|
||||
|
||||
async def get_chat_messages_page(
|
||||
store: MemoryStore,
|
||||
*,
|
||||
chat_id: UUID,
|
||||
after: CursorKey | None,
|
||||
limit: int,
|
||||
) -> list[dataclasses.MessageFullDTO]:
|
||||
"""До `limit + 1` сообщений чата строго после ключа `after`."""
|
||||
messages = store.messages_by_chat.get(chat_id, [])
|
||||
start = 0
|
||||
if after is not None:
|
||||
start = bisect.bisect_right(messages, after, key=_message_key)
|
||||
return messages[start : start + limit + 1]
|
||||
Reference in New Issue
Block a user