mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Do not dump the session data on the disk on every request.
Session object is updated, everytime a request is being served, and that was forcing the session object dumped on the dist on every request. On windows, it was causing issues on slower system on startup. Because - windows file system locks the file, when it is opened by any application. And, frequent requests on the pgAdmin main UI rendering was causing issues, because of that. In order to resolve the issue, we will not write the session data on disk for every request, but - only after certain delay (in seconds), from it was last written. It can be configured using the attribute 'PGADMIN_SESSION_DISK_WRITE_DELAY' in the configuration file, default vaule for the delay is 10. (i.e. 10 seconds)
This commit is contained in:
parent
178d583bcd
commit
d339d6b816
@ -22,6 +22,7 @@ import hashlib
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from uuid import uuid4
|
||||
|
||||
try:
|
||||
@ -56,6 +57,7 @@ class ManagedSession(CallbackDict, SessionMixin):
|
||||
self.new = new
|
||||
self.modified = False
|
||||
self.randval = randval
|
||||
self.last_write = None
|
||||
self.hmac_digest = hmac_digest
|
||||
|
||||
def sign(self, secret):
|
||||
@ -153,9 +155,10 @@ class CachingSessionManager(SessionManager):
|
||||
|
||||
class FileBackedSessionManager(SessionManager):
|
||||
|
||||
def __init__(self, path, secret):
|
||||
def __init__(self, path, secret, disk_write_delay):
|
||||
self.path = path
|
||||
self.secret = secret
|
||||
self.disk_write_delay = disk_write_delay
|
||||
if not os.path.exists(self.path):
|
||||
os.makedirs(self.path)
|
||||
|
||||
@ -212,10 +215,16 @@ class FileBackedSessionManager(SessionManager):
|
||||
)
|
||||
|
||||
def put(self, session):
|
||||
'Store a managed session'
|
||||
"""Store a managed session"""
|
||||
current_time = time.time()
|
||||
if not session.hmac_digest:
|
||||
session.sign(self.secret)
|
||||
else:
|
||||
if session.last_write is not None \
|
||||
and (current_time - float(session.last_write)) < self.disk_write_delay:
|
||||
return
|
||||
|
||||
session.last_write = current_time
|
||||
fname = os.path.join(self.path, session.sid)
|
||||
with open(fname, 'wb') as f:
|
||||
dump(
|
||||
@ -281,7 +290,8 @@ def create_session_interface(app, skip_paths=[]):
|
||||
CachingSessionManager(
|
||||
FileBackedSessionManager(
|
||||
app.config['SESSION_DB_PATH'],
|
||||
app.config['SECRET_KEY']
|
||||
app.config['SECRET_KEY'],
|
||||
app.config.get('PGADMIN_SESSION_DISK_WRITE_DELAY', 10)
|
||||
),
|
||||
1000
|
||||
), skip_paths,
|
||||
|
Loading…
Reference in New Issue
Block a user