From ddef8e59773d7e610860b3cd1567788bdc38cc92 Mon Sep 17 00:00:00 2001 From: nnayk <79224511+nnayk@users.noreply.github.com> Date: Thu, 7 Dec 2023 22:52:26 -0800 Subject: [PATCH] Modify db decorator --- Backend/db_access.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Backend/db_access.py b/Backend/db_access.py index 6ef062e..f0f3d93 100644 --- a/Backend/db_access.py +++ b/Backend/db_access.py @@ -21,13 +21,17 @@ load_dotenv() app = Flask(__name__) +db_lock = 0 +@app.before_request def db_connect(DB_URL=None): - # MongoDB connection - mongo_uri = DB_URL or os.environ.get("MONGO_URI") - connect(alias="default", host=mongo_uri) - return True + if not db_lock: + # MongoDB connection + mongo_uri = DB_URL or os.environ.get("MONGO_URI") + connect(alias="default", host=mongo_uri) + db_lock = 1 + return True class Response: