feat(gateway): add AsyncSessionDB offload facade

This commit is contained in:
yoniebans 2026-06-29 11:46:18 +02:00 committed by Teknium
parent 89daacb454
commit ea26f22710

View file

@ -14,6 +14,7 @@ Key design decisions:
- Session source tagging ('cli', 'telegram', 'discord', etc.) for filtering
"""
import asyncio
import json
import logging
import random
@ -5525,3 +5526,20 @@ class SessionDB:
(error[:500], session_id),
)
self._execute_write(_do)
class AsyncSessionDB:
"""Async door onto SessionDB: offloads each call via asyncio.to_thread so a blocking SQLite call never freezes the event loop. Generic forwarder — the audit confirms no method returns a live cursor/generator."""
def __init__(self, db: "SessionDB") -> None:
self._db = db
def __getattr__(self, name: str):
attr = getattr(self._db, name)
if not callable(attr):
return attr
async def _offloaded(*args, **kwargs):
return await asyncio.to_thread(attr, *args, **kwargs)
return _offloaded