forked from rDrama/rDrama
standardize g.db behavior
parent
f1288ba991
commit
532ebd3ac8
|
@ -51,6 +51,7 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
g.db.close()
|
g.db.close()
|
||||||
|
del g.db
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
def _sub_inactive_purge_task():
|
def _sub_inactive_purge_task():
|
||||||
|
|
|
@ -43,9 +43,10 @@ def after_request(response):
|
||||||
if CLOUDFLARE_AVAILABLE and CLOUDFLARE_COOKIE_VALUE and getattr(g, 'desires_auth', False):
|
if CLOUDFLARE_AVAILABLE and CLOUDFLARE_COOKIE_VALUE and getattr(g, 'desires_auth', False):
|
||||||
logged_in = bool(getattr(g, 'v', None))
|
logged_in = bool(getattr(g, 'v', None))
|
||||||
response.set_cookie("lo", CLOUDFLARE_COOKIE_VALUE if logged_in else '', max_age=60*60*24*365 if logged_in else 1)
|
response.set_cookie("lo", CLOUDFLARE_COOKIE_VALUE if logged_in else '', max_age=60*60*24*365 if logged_in else 1)
|
||||||
g.db.commit()
|
if getattr(g, 'db', None):
|
||||||
g.db.close()
|
g.db.commit()
|
||||||
del g.db
|
g.db.close()
|
||||||
|
del g.db
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
|
|
|
@ -48,7 +48,10 @@ def error_401(e):
|
||||||
|
|
||||||
@app.errorhandler(500)
|
@app.errorhandler(500)
|
||||||
def error_500(e):
|
def error_500(e):
|
||||||
g.db.rollback()
|
if getattr(g, 'db', None):
|
||||||
|
g.db.rollback()
|
||||||
|
g.db.close()
|
||||||
|
del g.db
|
||||||
return error(e)
|
return error(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ def authorize(v):
|
||||||
g.db.add(new_auth)
|
g.db.add(new_auth)
|
||||||
except sqlalchemy.exc.IntegrityError:
|
except sqlalchemy.exc.IntegrityError:
|
||||||
g.db.rollback()
|
g.db.rollback()
|
||||||
|
g.db.close()
|
||||||
|
del g.db
|
||||||
old_auth = g.db.query(ClientAuth).filter_by(oauth_client = application.id, user_id = v.id).one()
|
old_auth = g.db.query(ClientAuth).filter_by(oauth_client = application.id, user_id = v.id).one()
|
||||||
access_token = old_auth.access_token
|
access_token = old_auth.access_token
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue