Harden auth and persist report schedules

This commit is contained in:
dwindown
2026-06-06 19:40:32 +07:00
parent aaf64264f7
commit fd7989f673
18 changed files with 748 additions and 105 deletions

View File

@@ -715,7 +715,7 @@ async def generate_questions_batch(
return generated_items
async def get_ai_stats(db: AsyncSession) -> Dict[str, Any]:
async def get_ai_stats(db: AsyncSession, website_id: int | None = None) -> Dict[str, Any]:
"""
Get AI generation statistics.
@@ -725,16 +725,18 @@ async def get_ai_stats(db: AsyncSession) -> Dict[str, Any]:
Returns:
Statistics dictionary
"""
filters = [Item.generated_by == "ai"]
if website_id is not None:
filters.append(Item.website_id == website_id)
# Total AI-generated items
total_result = await db.execute(
select(func.count(Item.id)).where(Item.generated_by == "ai")
)
total_result = await db.execute(select(func.count(Item.id)).where(*filters))
total_ai_items = total_result.scalar() or 0
# Items by model
model_result = await db.execute(
select(Item.ai_model, func.count(Item.id))
.where(Item.generated_by == "ai")
.where(*filters)
.where(Item.ai_model.isnot(None))
.group_by(Item.ai_model)
)