mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 09:52:38 +02:00
🗃 — Make simpler DB query in get_agents_view
This commit is contained in:
parent
67d92499bb
commit
9ff2814789
1 changed files with 4 additions and 9 deletions
|
@ -5,7 +5,8 @@ from urllib.parse import urlparse
|
|||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from sqlalchemy.orm import Session, aliased
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from argos.schemas import Config
|
||||
from argos.server import queries
|
||||
|
@ -144,15 +145,9 @@ async def get_task_results_view(
|
|||
@route.get("/agents")
|
||||
async def get_agents_view(request: Request, db: Session = Depends(get_db)):
|
||||
"""Show argos agents and the last time the server saw them"""
|
||||
t1 = aliased(Result, name="t1")
|
||||
t2 = aliased(Result, name="t2")
|
||||
|
||||
last_seen = (
|
||||
db.query(t1)
|
||||
.outerjoin(
|
||||
t2, (t1.agent_id == t2.agent_id) & (t1.submitted_at < t2.submitted_at)
|
||||
)
|
||||
.filter(t2.agent_id.is_(None))
|
||||
db.query(Result.agent_id, func.max(Result.submitted_at).label('submitted_at'))
|
||||
.group_by(Result.agent_id)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue