Restore active sessions on startup
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import logging
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy import func, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.memory.models import (
|
||||
@@ -56,6 +56,16 @@ class Repository:
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalars().first()
|
||||
|
||||
async def get_active_sessions(self) -> list[StreamSession]:
|
||||
"""Retrieve sessions that are still marked active."""
|
||||
stmt = (
|
||||
select(StreamSession)
|
||||
.where(StreamSession.is_active.is_(True))
|
||||
.order_by(StreamSession.started_at.asc())
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
# Chat Message operations
|
||||
|
||||
async def add_chat_message(
|
||||
@@ -95,6 +105,14 @@ class Repository:
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def count_messages(self, session_id: str) -> int:
|
||||
"""Count chat messages stored for a session."""
|
||||
stmt = select(func.count()).select_from(ChatMessage).where(
|
||||
ChatMessage.session_id == session_id
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalar_one()
|
||||
|
||||
async def get_messages_since(
|
||||
self, session_id: str, since: datetime
|
||||
) -> list[ChatMessage]:
|
||||
|
||||
Reference in New Issue
Block a user