move code to reduce lock duration

master
Aevann 2023-08-10 21:47:57 +03:00
parent 9127b58a36
commit 9e16fcac3e
2 changed files with 7 additions and 10 deletions

View File

@ -61,6 +61,13 @@ def after_request(response):
if response.status_code < 400: if response.status_code < 400:
if hasattr(g, 'v') and g.v: if hasattr(g, 'v') and g.v:
user_id = g.v.id user_id = g.v.id
if not session.get("GLOBAL") and request.method == "POST":
timestamp = int(time.time())
if (g.v.last_active + LOGGEDIN_ACTIVE_TIME) < timestamp:
g.v.last_active = timestamp
g.db.add(g.v)
_commit_and_close_db() _commit_and_close_db()
if request.method == "POST": if request.method == "POST":

View File

@ -107,16 +107,6 @@ def get_logged_in_user():
g.v = v g.v = v
if v:
# Check against last_active + ACTIVE_TIME to reduce frequency of
# UPDATEs in exchange for a ±ACTIVE_TIME margin of error.
if not session.get("GLOBAL") and request.method == "POST":
timestamp = int(time.time())
if (v.last_active + LOGGEDIN_ACTIVE_TIME) < timestamp:
v.last_active = timestamp
g.db.add(v)
if not v and SITE == 'rdrama.net' and request.headers.get("Cf-Ipcountry") == 'EG' and request.method == 'GET' and request.full_path != '/login?nig=a': if not v and SITE == 'rdrama.net' and request.headers.get("Cf-Ipcountry") == 'EG' and request.method == 'GET' and request.full_path != '/login?nig=a':
abort(404) abort(404)