mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-17 14:42:06 +00:00
perf(db): cache SQLite schema init and optimize descendant traversal
- Cache SQLite schema initialization status process-wide in hermes_state.py to prevent redundant column reconciliations and FTS probe queries on every SessionDB connection creation. This eliminates SQLite lock contention under high concurrent requests (e.g. status polls). Bypassed in pytest/unittest environments for mock compatibility. - Optimize the _session_latest_descendant query in hermes_cli/web_server.py using a recursive CTE (WITH RECURSIVE) to query only descendants of the target session. This avoids downloading and parsing all historical sessions in Python.
This commit is contained in:
parent
62f0cfd902
commit
8ed5e54f65
2 changed files with 25 additions and 2 deletions
|
|
@ -4478,7 +4478,17 @@ def _session_latest_descendant(session_id: str):
|
|||
rows = []
|
||||
if conn is not None:
|
||||
raw_rows = conn.execute(
|
||||
"SELECT id, parent_session_id, started_at FROM sessions"
|
||||
"""
|
||||
WITH RECURSIVE descendants(id, parent_session_id, started_at) AS (
|
||||
SELECT id, parent_session_id, started_at FROM sessions WHERE id = ?
|
||||
UNION ALL
|
||||
SELECT s.id, s.parent_session_id, s.started_at
|
||||
FROM sessions s
|
||||
JOIN descendants d ON s.parent_session_id = d.id
|
||||
)
|
||||
SELECT id, parent_session_id, started_at FROM descendants WHERE id != ?
|
||||
""",
|
||||
(sid, sid)
|
||||
).fetchall()
|
||||
for row in raw_rows:
|
||||
rows.append({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue