mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-05-21 15:14:45 +02:00
Support unlimited message history when max_messages_per_user is 0
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
69b749930c
commit
6b1320f9e0
1 changed files with 24 additions and 10 deletions
|
|
@ -110,16 +110,27 @@ class ConversationHistory:
|
|||
cutoff_time = time.time() - self.config.conversation_timeout
|
||||
|
||||
async with self._lock:
|
||||
cursor = await self._db.execute(
|
||||
"""
|
||||
SELECT role, content, timestamp
|
||||
FROM conversations
|
||||
WHERE user_id = ? AND timestamp > ?
|
||||
ORDER BY timestamp ASC
|
||||
LIMIT ?
|
||||
""",
|
||||
(user_id, cutoff_time, self.config.max_messages_per_user * 2),
|
||||
)
|
||||
if self.config.max_messages_per_user > 0:
|
||||
cursor = await self._db.execute(
|
||||
"""
|
||||
SELECT role, content, timestamp
|
||||
FROM conversations
|
||||
WHERE user_id = ? AND timestamp > ?
|
||||
ORDER BY timestamp ASC
|
||||
LIMIT ?
|
||||
""",
|
||||
(user_id, cutoff_time, self.config.max_messages_per_user * 2),
|
||||
)
|
||||
else:
|
||||
cursor = await self._db.execute(
|
||||
"""
|
||||
SELECT role, content, timestamp
|
||||
FROM conversations
|
||||
WHERE user_id = ? AND timestamp > ?
|
||||
ORDER BY timestamp ASC
|
||||
""",
|
||||
(user_id, cutoff_time),
|
||||
)
|
||||
|
||||
rows = await cursor.fetchall()
|
||||
|
||||
|
|
@ -161,6 +172,9 @@ class ConversationHistory:
|
|||
|
||||
async def _prune_history(self, user_id: str) -> None:
|
||||
"""Remove old messages beyond the limit for a user."""
|
||||
if self.config.max_messages_per_user <= 0:
|
||||
return # No limit
|
||||
|
||||
# Get count of messages for user
|
||||
cursor = await self._db.execute(
|
||||
"SELECT COUNT(*) FROM conversations WHERE user_id = ?",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue