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
+4 -18
View File
@@ -3,22 +3,11 @@
from quart import Blueprint, jsonify, request
from sqlalchemy import func, select
from ..extensions import make_engine, make_session_factory
from ..extensions import get_session
from ..models import ImageRecord, ImportBatch, ImportSettings, ImportTask, Tag
settings_bp = Blueprint("settings", __name__, url_prefix="/api")
_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_FIELDS = (
"min_width",
@@ -33,8 +22,7 @@ _EDITABLE_FIELDS = (
@settings_bp.route("/settings/import", methods=["GET"])
async def get_import_settings():
Session = _session_factory()
async with Session() as session:
async with get_session() as session:
row = (
await session.execute(select(ImportSettings).where(ImportSettings.id == 1))
).scalar_one()
@@ -55,8 +43,7 @@ async def update_import_settings():
if not isinstance(body, dict):
return jsonify({"error": "body must be a JSON object"}), 400
Session = _session_factory()
async with Session() as session:
async with get_session() as session:
row = (
await session.execute(select(ImportSettings).where(ImportSettings.id == 1))
).scalar_one()
@@ -70,8 +57,7 @@ async def update_import_settings():
@settings_bp.route("/system/stats", methods=["GET"])
async def system_stats():
Session = _session_factory()
async with Session() as session:
async with get_session() as session:
total_images = (await session.execute(select(func.count(ImageRecord.id)))).scalar_one()
total_tags = (await session.execute(select(func.count(Tag.id)))).scalar_one()
storage_bytes = (