Files
lollms_hub/app/database/session.py
Saifeddine ALOUI 7b6233349e feat: Implement core bot management, admin routes, and model metadata CRUD
This commit introduces several related updates across the application, focusing on establishing core functionality for bot management, admin routing, and metadata handling.

Key changes include:
- Updating API routes for admin and proxy functionality.
- Refactoring the `BotManager` to handle the starting of active bots.
- Implementing necessary CRUD operations for model metadata and server information.
- Updating database migration and session management files.
- Adjusting relevant template files for the admin dashboard display.
2026-04-19 04:05:00 +02:00

36 lines
1.3 KiB
Python

from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
from app.core.config import settings
engine = create_async_engine(
settings.DATABASE_URL,
pool_pre_ping=True,
# For SQLite/aiosqlite, we avoid pool_size/max_overflow unless using a specific Pool class.
# Default parameters are safer for file-based locking.
connect_args={
"timeout": 30,
"check_same_thread": False # Required for aiosqlite/multithreading
}
)
# --- SPACE OPTIMIZATION ---
from sqlalchemy import event
@event.listens_for(engine.sync_engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
# WAL mode allows concurrent reads and writes without locking
cursor.execute("PRAGMA journal_mode = WAL")
# Limit journal size to 2MB to prevent disk exhaustion
cursor.execute("PRAGMA journal_size_limit = 2097152")
# Synchronous NORMAL is safe and much faster in WAL mode
cursor.execute("PRAGMA synchronous = NORMAL")
cursor.close()
AsyncSessionLocal = async_sessionmaker(
autocommit=False, autoflush=False, bind=engine, class_=AsyncSession, expire_on_commit=False
)
async def get_db():
async with AsyncSessionLocal() as session:
yield session