diff --git a/meshinfo/views/iperf.py b/meshinfo/views/iperf.py index 7773ddd..4e59c7a 100644 --- a/meshinfo/views/iperf.py +++ b/meshinfo/views/iperf.py @@ -2,6 +2,7 @@ from pyramid.request import Request from pyramid.view import view_config +from sqlalchemy import sql from sqlalchemy.orm import Session from ..models import Node @@ -12,5 +13,7 @@ def overview(request: Request): dbsession: Session = request.dbsession - nodes = dbsession.query(Node).filter(Node.status != NodeStatus.INACTIVE).all() + nodes = dbsession.execute( + sql.select(Node).where(Node.status != NodeStatus.INACTIVE) + ).scalars() return {"nodes": nodes} diff --git a/meshinfo/views/link.py b/meshinfo/views/link.py index 85e257f..4b5e2da 100644 --- a/meshinfo/views/link.py +++ b/meshinfo/views/link.py @@ -24,15 +24,14 @@ def link_preview(request: Request): type_ = getattr(LinkType, request.matchdict["type"].upper()) dbsession: Session = request.dbsession - link = ( - dbsession.query(Link) - .options( + link = dbsession.get( + Link, + (source_id, destination_id, type_), + options=[ joinedload(Link.source).load_only(Node.name), joinedload(Link.destination).load_only(Node.name), - ) - .get((source_id, destination_id, type_)) + ], ) - if link is None: raise HTTPNotFound("Sorry, the specified link could not be found") @@ -61,13 +60,13 @@ def link_graphs(request: Request): dbsession: Session = request.dbsession graph = request.matchdict["name"] - link = ( - dbsession.query(Link) - .options( + link = dbsession.get( + Link, + (source_id, destination_id, type_), + options=[ load_only(Link.source_id, Link.destination_id), joinedload(Link.destination).load_only(Node.name), - ) - .get((source_id, destination_id, type_)) + ], ) if link is None: raise HTTPNotFound("Sorry, the specified link could not be found") @@ -89,21 +88,20 @@ def __init__(self, request: Request): type_ = getattr(LinkType, request.matchdict["type"].upper()) dbsession: Session = request.dbsession - self.link = ( - dbsession.query(Link) - .options( + link = dbsession.get( + Link, + (source_id, destination_id, type_), + options=[ load_only(Link.source_id, Link.destination_id, Link.type), joinedload(Link.destination).load_only(Node.name), - ) - .get((source_id, destination_id, type_)) + ], ) - if self.link is None: + if link is None: raise HTTPNotFound("Sorry, the specified link could not be found") + self.link = link self.name_in_title = asbool(request.GET.get("name_in_title", False)) - self.graph_params = schema.graph_params(request.GET) - self.stats: HistoricalStats = request.find_service(HistoricalStats) @view_config(match_param="name=cost")