Compare commits

...

2 Commits

2 changed files with 25 additions and 2 deletions

View File

@@ -45,7 +45,7 @@ while IFS= read -r line; do
if PSYC_PROD_HOST="$SSH_TARGET" \ if PSYC_PROD_HOST="$SSH_TARGET" \
PSYC_PROD_PATH="$REMOTE_PATH" \ PSYC_PROD_PATH="$REMOTE_PATH" \
PSYC_PROD_URL="$PUBLIC_URL" \ PSYC_PROD_URL="$PUBLIC_URL" \
bash "$(dirname "$0")/deploy.sh"; then bash "$(dirname "$0")/deploy.sh" < /dev/null; then
OK+=("$LABEL") OK+=("$LABEL")
else else
FAIL+=("$LABEL") FAIL+=("$LABEL")

View File

@@ -17,11 +17,13 @@ from sqlalchemy import (
Table, Table,
Text, Text,
create_engine, create_engine,
event,
func, func,
insert, insert,
select, select,
) )
from sqlalchemy.dialects.sqlite import insert as sqlite_insert from sqlalchemy.dialects.sqlite import insert as sqlite_insert
from sqlalchemy.pool import NullPool
from psyc import DATA_DIR, log from psyc import DATA_DIR, log
from psyc.models import Case from psyc.models import Case
@@ -209,10 +211,31 @@ _engine: Optional[Engine] = None
def engine(db_path: Path = DB_PATH) -> Engine: def engine(db_path: Path = DB_PATH) -> Engine:
"""Lazy-init the SQLite engine.
Uses NullPool — SQLite doesn't benefit from connection pooling (it's a
file, opens are cheap) and the default QueuePool starved the classify +
federation + cockpit-request workers under real load. WAL journal mode
+ a 30s busy timeout let readers and a writer share the file safely.
"""
global _engine global _engine
if _engine is None: if _engine is None:
db_path.parent.mkdir(parents=True, exist_ok=True) db_path.parent.mkdir(parents=True, exist_ok=True)
_engine = create_engine(f"sqlite:///{db_path}", future=True) _engine = create_engine(
f"sqlite:///{db_path}",
future=True,
poolclass=NullPool,
connect_args={"check_same_thread": False, "timeout": 30},
)
@event.listens_for(_engine, "connect")
def _sqlite_pragmas(dbapi_conn, _connection_record): # noqa: D401
cur = dbapi_conn.cursor()
cur.execute("PRAGMA journal_mode=WAL")
cur.execute("PRAGMA synchronous=NORMAL")
cur.execute("PRAGMA busy_timeout=30000")
cur.close()
return _engine return _engine