fix(sessions): handle separate ways of session expiry in postgres and mariadb
This commit is contained in:
parent
7107f335f2
commit
d92606cea9
2 changed files with 9 additions and 3 deletions
|
|
@ -13,7 +13,7 @@ window.cint = function(v, def) {
|
|||
return 0;
|
||||
v = v + '';
|
||||
if (v !== "0") v = lstrip(v, ['0']);
|
||||
v = parseInt(v);
|
||||
v = parseInt(v); // eslint-ignore-line
|
||||
if (isNaN(v)) v = def === undefined ? 0 : def;
|
||||
return v;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ def get_expired_sessions():
|
|||
expired += frappe.db.sql_list("""SELECT `sid`
|
||||
FROM `tabSessions`
|
||||
WHERE (NOW() - `lastupdate`) > %s
|
||||
AND device = %s""", (get_expiry_in_seconds(device = device), device))
|
||||
AND device = %s""", (get_expiry_period_for_query(device), device))
|
||||
|
||||
return expired
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ class Session:
|
|||
SELECT `user`, `sessiondata`
|
||||
FROM `tabSessions` WHERE `sid`=%s AND
|
||||
(NOW() - lastupdate) < %s
|
||||
""", (self.sid, get_expiry_in_seconds(device = self.device)), debug=1)
|
||||
""", (self.sid, get_expiry_period_for_query(self.device)), debug=1)
|
||||
|
||||
if rec:
|
||||
data = frappe._dict(eval(rec and rec[0][1] or '{}'))
|
||||
|
|
@ -376,6 +376,12 @@ class Session:
|
|||
|
||||
return updated_in_db
|
||||
|
||||
def get_expiry_period_for_query(device=None):
|
||||
if frappe.db.db_type == 'postgres':
|
||||
return get_expiry_period(device)
|
||||
else:
|
||||
return get_expiry_in_seconds(device=device)
|
||||
|
||||
def get_expiry_in_seconds(expiry=None, device=None):
|
||||
if not expiry:
|
||||
expiry = get_expiry_period(device)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue