Skip to content

Commit

Permalink
add containers eager to reading api query
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Mar 22, 2024
1 parent 354625f commit cdcdc53
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nowcasting_datamodel/read/read_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from typing import List, Optional

from sqlalchemy.orm import contains_eager
from sqlalchemy.orm.session import Session

from nowcasting_datamodel.models.api import APIRequestSQL, UserSQL
Expand Down Expand Up @@ -57,6 +58,7 @@ def get_all_last_api_request(session: Session) -> List[APIRequestSQL]:
session.query(APIRequestSQL)
.distinct(APIRequestSQL.user_uuid)
.join(UserSQL)
.options(contains_eager(APIRequestSQL.user)).populate_existing()
.order_by(APIRequestSQL.user_uuid, APIRequestSQL.created_utc.desc())
.all()
)
Expand Down

0 comments on commit cdcdc53

Please sign in to comment.