Skip to content

Commit

Permalink
Modify db decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
nnayk committed Dec 8, 2023
1 parent e5d4e2b commit ddef8e5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Backend/db_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ddef8e5

Please sign in to comment.