refactor(fc2c-i): sweep blueprints + ml tasks onto shared get_session (covers tasks/ml.py, a survey gap)

This commit is contained in:
2026-05-15 15:48:02 -04:00
parent fc33c23dd5
commit f7f75fcac6
9 changed files with 42 additions and 164 deletions
+3 -16
View File
@@ -2,22 +2,11 @@
from quart import Blueprint, jsonify, request
from ..extensions import make_engine, make_session_factory
from ..extensions import get_session
from ..models import MLSettings
ml_admin_bp = Blueprint("ml_admin", __name__, url_prefix="/api/ml")
_engine = None
_Session = None
def _session_factory():
global _engine, _Session
if _engine is None:
_engine = make_engine()
_Session = make_session_factory(_engine)
return _Session
_EDITABLE = (
"suggestion_threshold_artist",
@@ -33,8 +22,7 @@ _EDITABLE = (
async def get_settings():
from sqlalchemy import select
Session = _session_factory()
async with Session() as session:
async with get_session() as session:
s = (
await session.execute(select(MLSettings).where(MLSettings.id == 1))
).scalar_one()
@@ -59,8 +47,7 @@ async def patch_settings():
body = await request.get_json()
if not isinstance(body, dict):
return jsonify({"error": "body must be an object"}), 400
Session = _session_factory()
async with Session() as session:
async with get_session() as session:
s = (
await session.execute(select(MLSettings).where(MLSettings.id == 1))
).scalar_one()