From 0b60f104b11880330e49821c4b40909e064ddd4e Mon Sep 17 00:00:00 2001 From: Benyamin Date: Wed, 29 Nov 2023 17:44:24 +0330 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20optimized=20the=20query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ifsguid/crud.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ifsguid/crud.py b/ifsguid/crud.py index e91b140..7decef3 100644 --- a/ifsguid/crud.py +++ b/ifsguid/crud.py @@ -1,7 +1,7 @@ from typing import List from uuid import UUID -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, joinedload from . import models, schemas, utils @@ -9,7 +9,9 @@ def get_interactions( db: Session, page: int = None, per_page: int = 10 ) -> List[models.Interaction]: - query = db.query(models.Interaction) + query = db.query(models.Interaction).options( + joinedload(models.Interaction.messages) + ) if page is not None: query = query.offset((page - 1) * per_page).limit(per_page)