crud: use indexed primary key search rather than list all

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-04-18 01:54:33 +03:00
parent f5d7db5071
commit 20f4d0202f

View File

@ -11,7 +11,7 @@ from . import models, schemas, crypto, auth_helper
# - Any polling from IotEntity? Maybe to much data
def get_user(db: Session, user_id: int):
return db.query(models.User).filter(models.User.id == user_id).first()
return db.query(models.User).get(user_id)
def get_iot_entity(db: Session, id: int):
return db.query(models.IotEntity).filter(models.IotEntity.id == id).first()