Skip to content

Commit

Permalink
add container eager (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield authored Mar 12, 2024
1 parent 6cbd1dc commit a0c475a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pvsite_datamodel/read/latest_forecast_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Optional, Union

from sqlalchemy import func
from sqlalchemy.orm import Session
from sqlalchemy.orm import Session, contains_eager

from pvsite_datamodel.pydantic_models import ForecastValueSum
from pvsite_datamodel.sqlmodels import ForecastSQL, ForecastValueSQL, SiteSQL
Expand Down Expand Up @@ -69,6 +69,9 @@ def get_latest_forecast_values_by_site(
if forecast_horizon_minutes is not None:
query = query.filter(ForecastValueSQL.horizon_minutes == forecast_horizon_minutes)

# speed up query, so all information is gather in one query, rather than lots of little ones
query = query.options(contains_eager(ForecastValueSQL.forecast)).populate_existing()

query = query.order_by(
ForecastSQL.site_uuid,
ForecastValueSQL.start_utc,
Expand Down

0 comments on commit a0c475a

Please sign in to comment.