仪表盘展示最新运行快照
This commit is contained in:
+19
-3
@@ -98,14 +98,25 @@ def latest_report(db: Session = Depends(get_db)) -> Optional[Report]:
|
||||
def dashboard(db: Session = Depends(get_db)) -> DashboardRead:
|
||||
# 单个仪表盘接口返回运行、信号、日报和主题,前端不需要理解内部调度细节。
|
||||
runs = list(db.scalars(select(AgentRun).order_by(AgentRun.id.desc()).limit(10)).all())
|
||||
latest_completed_run = db.scalar(
|
||||
select(AgentRun)
|
||||
.where(AgentRun.status == "completed")
|
||||
.order_by(AgentRun.id.desc())
|
||||
.limit(1)
|
||||
)
|
||||
latest_run_id = latest_completed_run.id if latest_completed_run is not None else None
|
||||
news_signals = list(
|
||||
db.scalars(
|
||||
_visible_signals_query(source_type="news").order_by(Signal.id.desc()).limit(80)
|
||||
_visible_signals_query(source_type="news", run_id=latest_run_id)
|
||||
.order_by(Signal.id.desc())
|
||||
.limit(80)
|
||||
).all()
|
||||
)
|
||||
github_signals = list(
|
||||
db.scalars(
|
||||
_visible_signals_query(source_type="github").order_by(Signal.id.desc()).limit(80)
|
||||
_visible_signals_query(source_type="github", run_id=latest_run_id)
|
||||
.order_by(Signal.id.desc())
|
||||
.limit(80)
|
||||
).all()
|
||||
)
|
||||
report = db.scalar(select(Report).order_by(Report.id.desc()).limit(1))
|
||||
@@ -144,9 +155,14 @@ def list_topics(db: Session = Depends(get_db)) -> list[Topic]:
|
||||
return list(db.scalars(select(Topic).order_by(Topic.id.asc())).all())
|
||||
|
||||
|
||||
def _visible_signals_query(source_type: Optional[Literal["news", "github"]] = None):
|
||||
def _visible_signals_query(
|
||||
source_type: Optional[Literal["news", "github"]] = None,
|
||||
run_id: Optional[int] = None,
|
||||
):
|
||||
# 运行中的信号和完成后的信号走同一张表,查询函数保留统一排序入口。
|
||||
query = select(Signal).join(AgentRun, Signal.run_id == AgentRun.id)
|
||||
if source_type is not None:
|
||||
query = query.where(Signal.source_type == source_type)
|
||||
if run_id is not None:
|
||||
query = query.where(Signal.run_id == run_id)
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user