From 9e16fcac3eb56c0ad5ec7e7ec096754276220f6e Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 10 Aug 2023 21:47:57 +0300 Subject: [PATCH] move code to reduce lock duration --- files/routes/allroutes.py | 7 +++++++ files/routes/wrappers.py | 10 ---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/files/routes/allroutes.py b/files/routes/allroutes.py index 5cf5caad0..b079c953f 100644 --- a/files/routes/allroutes.py +++ b/files/routes/allroutes.py @@ -61,6 +61,13 @@ def after_request(response): if response.status_code < 400: if hasattr(g, 'v') and g.v: 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() if request.method == "POST": diff --git a/files/routes/wrappers.py b/files/routes/wrappers.py index d3269dbb0..087f0b053 100644 --- a/files/routes/wrappers.py +++ b/files/routes/wrappers.py @@ -107,16 +107,6 @@ def get_logged_in_user(): 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': abort(404)