Skip to content

Commit

Permalink
Update a couple pages to use 2.0 select statements
Browse files Browse the repository at this point in the history
  • Loading branch information
smsearcy committed Jul 25, 2024
1 parent 7b3ecfb commit 5ebda4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
5 changes: 4 additions & 1 deletion meshinfo/views/iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
36 changes: 17 additions & 19 deletions meshinfo/views/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 5ebda4c

Please sign in to comment.