Merge pull request #1704 from NousResearch/fix/hermes-state-thread-locks
fix(state): add missing thread locks to 4 SessionDB methods
This commit is contained in:
commit
ed3bcae8bd
1 changed files with 48 additions and 44 deletions
|
|
@ -809,6 +809,7 @@ class SessionDB:
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""List sessions, optionally filtered by source."""
|
"""List sessions, optionally filtered by source."""
|
||||||
|
with self._lock:
|
||||||
if source:
|
if source:
|
||||||
cursor = self._conn.execute(
|
cursor = self._conn.execute(
|
||||||
"SELECT * FROM sessions WHERE source = ? ORDER BY started_at DESC LIMIT ? OFFSET ?",
|
"SELECT * FROM sessions WHERE source = ? ORDER BY started_at DESC LIMIT ? OFFSET ?",
|
||||||
|
|
@ -871,6 +872,7 @@ class SessionDB:
|
||||||
|
|
||||||
def clear_messages(self, session_id: str) -> None:
|
def clear_messages(self, session_id: str) -> None:
|
||||||
"""Delete all messages for a session and reset its counters."""
|
"""Delete all messages for a session and reset its counters."""
|
||||||
|
with self._lock:
|
||||||
self._conn.execute(
|
self._conn.execute(
|
||||||
"DELETE FROM messages WHERE session_id = ?", (session_id,)
|
"DELETE FROM messages WHERE session_id = ?", (session_id,)
|
||||||
)
|
)
|
||||||
|
|
@ -882,6 +884,7 @@ class SessionDB:
|
||||||
|
|
||||||
def delete_session(self, session_id: str) -> bool:
|
def delete_session(self, session_id: str) -> bool:
|
||||||
"""Delete a session and all its messages. Returns True if found."""
|
"""Delete a session and all its messages. Returns True if found."""
|
||||||
|
with self._lock:
|
||||||
cursor = self._conn.execute(
|
cursor = self._conn.execute(
|
||||||
"SELECT COUNT(*) FROM sessions WHERE id = ?", (session_id,)
|
"SELECT COUNT(*) FROM sessions WHERE id = ?", (session_id,)
|
||||||
)
|
)
|
||||||
|
|
@ -900,6 +903,7 @@ class SessionDB:
|
||||||
import time as _time
|
import time as _time
|
||||||
cutoff = _time.time() - (older_than_days * 86400)
|
cutoff = _time.time() - (older_than_days * 86400)
|
||||||
|
|
||||||
|
with self._lock:
|
||||||
if source:
|
if source:
|
||||||
cursor = self._conn.execute(
|
cursor = self._conn.execute(
|
||||||
"""SELECT id FROM sessions
|
"""SELECT id FROM sessions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue