From f37b7392e232e4fc59b9e26df445690724957ccc Mon Sep 17 00:00:00 2001 From: coolneng Date: Sun, 4 Oct 2020 16:42:18 +0200 Subject: [PATCH] Remove redundant DB query on account activation --- database/crud.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/database/crud.py b/database/crud.py index 1eb554c..404344d 100644 --- a/database/crud.py +++ b/database/crud.py @@ -60,12 +60,16 @@ def update_otp(data: OTPResend, db): db.commit() -def activate_account(data: OTPVerify, db): - db.query(Users).filter(Users.access_key == data.access_key).update( + ) + return user + + +def activate_account(user, db): + db.query(Users).filter(Users.access_key == user.access_key).update( {Users.status: 1} ) - user = fetch_user_by_key(data=data, db=db) - return user + db.commit() + db.refresh(user) def verify_otp(data: OTPVerify, db): @@ -74,7 +78,7 @@ def verify_otp(data: OTPVerify, db): valid_time = datetime.now() < user.otp_valid_time valid_otp = matching_otp and valid_time if valid_otp: - result = activate_account(data=data, db=db) - return result + activate_account(user=user, db=db) + return user else: raise HTTPException(status_code=400, detail="The OTP is not correct")