This commit is contained in:
Mikan
2026-06-21 02:41:48 +03:00
parent c21a13d2a3
commit bd85e186dc
31 changed files with 1372 additions and 319 deletions

View File

@@ -152,6 +152,34 @@ async def patch_user(
return {"id": str(user.id), "is_admin": user.is_admin, "is_active": user.is_active}
@router.delete("/worlds/{world_id}", status_code=200)
async def hard_delete_world(
world_id: uuid.UUID,
db: AsyncSession = Depends(get_db),
_user: User = Depends(require_admin),
) -> dict:
"""Hard-delete a world (cascade deletes all related entities, steps, logs).
Also cleans up Qdrant points for the world (best-effort).
"""
from app.models import World
from app.core.qdrant_client import cleanup_world_points
world = (
await db.execute(select(World).where(World.id == world_id))
).scalar_one_or_none()
if world is None:
raise HTTPException(404, "not_found")
await db.delete(world)
await db.commit()
# Best-effort Qdrant cleanup
try:
await cleanup_world_points(str(world_id))
except Exception as e: # noqa: BLE001
_logger.warning("qdrant_cleanup_failed", world_id=str(world_id), error=str(e))
return {"ok": True, "deleted": str(world_id)}
# --------------------------------------------------------------------------- #
# Stats
# --------------------------------------------------------------------------- #
@@ -163,14 +191,27 @@ async def stats(
from app.models import Step, World
users_count = (await db.execute(select(func.count(User.id)))).scalar_one()
worlds_count = (await db.execute(select(func.count(World.id)))).scalar_one()
# Active worlds (exclude archived)
active_worlds = (
await db.execute(
select(func.count(World.id)).where(World.status != "archived")
)
).scalar_one()
archived_worlds = (
await db.execute(
select(func.count(World.id)).where(World.status == "archived")
)
).scalar_one()
total_worlds = active_worlds + archived_worlds
steps_count = (await db.execute(select(func.count(Step.id)))).scalar_one()
avg_latency = (
await db.execute(select(func.avg(LlmCallLog.latency_ms)))
).scalar_one()
return {
"users": users_count,
"worlds": worlds_count,
"worlds": active_worlds,
"worlds_total": total_worlds,
"worlds_archived": archived_worlds,
"steps": steps_count,
"avg_llm_latency_ms": float(avg_latency) if avg_latency else 0,
}