forked from mtusi2026/mtusi2026lab3
Add second lab code
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
"""Synthetic message history shared by EXPLAIN and cache measurements."""
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from sqlalchemy import insert, update
|
||||
|
||||
from src.models import Chat, Message
|
||||
|
||||
|
||||
def seed_messages(session, chat_id, user_id, count=10000):
|
||||
start = datetime(2026, 1, 1, tzinfo=timezone.utc)
|
||||
session.execute(insert(Message), [
|
||||
{'chat_id': chat_id, 'sender_id': user_id, 'text': 'synthetic ' * 100,
|
||||
'created_at': start + timedelta(milliseconds=n)}
|
||||
for n in range(1, count + 1)
|
||||
])
|
||||
session.execute(update(Chat).where(Chat.id == chat_id).values(
|
||||
history_version=Chat.history_version + 1))
|
||||
Reference in New Issue
Block a user