polish for failed retry mechanic and consistent sub naming

This commit is contained in:
2026-02-04 15:02:50 -05:00
parent 2190a9c16b
commit 055808ea6d
6 changed files with 82 additions and 21 deletions
+34 -5
View File
@@ -29,8 +29,10 @@ async def list_downloads():
async with current_app.db_engine.connect() as conn:
session = AsyncSession(bind=conn)
# Build query
query = select(Download)
# Build query - eager load source and subscription for labeling
query = select(Download).options(
selectinload(Download.source).selectinload(Source.subscription)
)
count_query = select(func.count()).select_from(Download)
filters = []
@@ -58,8 +60,20 @@ async def list_downloads():
result = await session.execute(query)
downloads = result.scalars().all()
# Include source info with each download
items = []
for d in downloads:
item = d.to_dict()
if d.source:
item["subscription_name"] = d.source.subscription.name if d.source.subscription else None
item["platform"] = d.source.platform
else:
item["subscription_name"] = None
item["platform"] = None
items.append(item)
return jsonify({
"items": [d.to_dict() for d in downloads],
"items": items,
"total": total,
"page": page,
"per_page": per_page,
@@ -147,8 +161,11 @@ async def recent_activity():
session = AsyncSession(bind=conn)
# Get failed downloads OR completed with files (noteworthy activity)
# Eager load source and subscription for labeling
from sqlalchemy import or_
query = select(Download).where(
query = select(Download).options(
selectinload(Download.source).selectinload(Source.subscription)
).where(
and_(
Download.created_at >= cutoff,
or_(
@@ -164,8 +181,20 @@ async def recent_activity():
result = await session.execute(query)
downloads = result.scalars().all()
# Include source info with each download
items = []
for d in downloads:
item = d.to_dict()
if d.source:
item["subscription_name"] = d.source.subscription.name if d.source.subscription else None
item["platform"] = d.source.platform
else:
item["subscription_name"] = None
item["platform"] = None
items.append(item)
return jsonify({
"items": [d.to_dict() for d in downloads],
"items": items,
"count": len(downloads),
})