fix(project-detail): show all-time data when no date range given

Default 30d window hid projects inactive for >30 days (e.g. Enterprise Ai Hub
Nexus, last session 2026-04-01). Project detail now returns all history unless
explicit from/to params are passed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-07 12:52:51 +01:00
parent e401f9a60b
commit e16e4a16a5

View file

@ -368,30 +368,24 @@ async def project_detail(
from fastapi import HTTPException
raise HTTPException(status_code=404, detail="Project not found")
from_date, to_date = _date_range(from_date, to_date)
# When no date range given, show all-time data for the project
date_filter_given = from_date is not None or to_date is not None
if date_filter_given:
from_date, to_date = _date_range(from_date, to_date)
stats_where = [DailyStat.user_id == user.id, DailyStat.project_id == project_id]
sessions_where = [Session.user_id == user.id, Session.project_id == project_id]
if date_filter_given:
stats_where += [DailyStat.date >= from_date, DailyStat.date <= to_date]
sessions_where += [Session.date >= from_date, Session.date <= to_date]
stats_result = await db.execute(
select(DailyStat)
.where(
DailyStat.user_id == user.id,
DailyStat.project_id == project_id,
DailyStat.date >= from_date,
DailyStat.date <= to_date,
)
.order_by(DailyStat.date)
select(DailyStat).where(*stats_where).order_by(DailyStat.date)
)
stats = stats_result.scalars().all()
sessions_result = await db.execute(
select(Session)
.where(
Session.user_id == user.id,
Session.project_id == project_id,
Session.date >= from_date,
Session.date <= to_date,
)
.order_by(Session.start_at.desc())
.limit(200)
select(Session).where(*sessions_where).order_by(Session.start_at.desc()).limit(200)
)
sessions = sessions_result.scalars().all()