Skip to content

Commit

Permalink
🗃️ DB-Timeout Fix
Browse files Browse the repository at this point in the history
Forgot to close the DB-Connection a bunch of times...
  • Loading branch information
pheeef committed May 29, 2021
1 parent 37b531a commit 46e5e87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion assets/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def openDBConnection():
host=e.db_host,
user=e.db_username,
passwd=e.db_password,
database=e.db_database
database=e.db_database,
autocommit=True,
connect_timeout=900
)
return db

Expand Down
6 changes: 3 additions & 3 deletions functions/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from assets.database import datasource
from models.app import App

ds = datasource()
ds.connect()


def getApp(ID: Optional[int] = None, NAME: Optional[str] = None, API_KEY: Optional[str] = None):
ds = datasource()
ds.connect()
global SQL, PARAM
if ID is not None:
SQL = "SELECT * FROM toolbox.APPS WHERE ID = %s"
Expand All @@ -20,4 +19,5 @@ def getApp(ID: Optional[int] = None, NAME: Optional[str] = None, API_KEY: Option
PARAM = (API_KEY,)
ds.execute(SQL, PARAM)
data = ds.fetch_dict()
ds.close()
return App(**data)
3 changes: 3 additions & 0 deletions functions/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_user(ID: Optional[int] = None, EMAIL: Optional[str] = None, TEMPHASH: Op
else:
raise ValueError('USER not Valid')
data = ds.fetch_row()
ds.close()
if data is not None:
return fetch_data(data)
else:
Expand Down Expand Up @@ -113,6 +114,7 @@ def is_teacher(EMAIL: str):
ds.execute("SELECT EMAIL FROM GLOBAL_TEACHERS WHERE EMAIL = %s", (EMAIL,))

data: str = ds.fetch_row()
ds.close()

if data is not None:
if data[0].casefold() == EMAIL.casefold():
Expand All @@ -130,6 +132,7 @@ def get_all_users():
allUsers = dict()

data = ds.fetch_all()
ds.close()

for x in data:
allUsers[x[0]] = fetch_data(x)
Expand Down

0 comments on commit 46e5e87

Please sign in to comment.