refac/fix: DATABASE_ENABLE_SESSION_SHARING env var
This commit is contained in:
@@ -341,6 +341,11 @@ if DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL is not None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = 0.0
|
DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = 0.0
|
||||||
|
|
||||||
|
# When enabled, get_db_context reuses existing sessions; set to False to always create new sessions
|
||||||
|
DATABASE_ENABLE_SESSION_SHARING = (
|
||||||
|
os.environ.get("DATABASE_ENABLE_SESSION_SHARING", "False").lower() == "true"
|
||||||
|
)
|
||||||
|
|
||||||
# Enable public visibility of active user count (when disabled, only admins can see it)
|
# Enable public visibility of active user count (when disabled, only admins can see it)
|
||||||
ENABLE_PUBLIC_ACTIVE_USERS_COUNT = (
|
ENABLE_PUBLIC_ACTIVE_USERS_COUNT = (
|
||||||
os.environ.get("ENABLE_PUBLIC_ACTIVE_USERS_COUNT", "True").lower() == "true"
|
os.environ.get("ENABLE_PUBLIC_ACTIVE_USERS_COUNT", "True").lower() == "true"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from open_webui.env import (
|
|||||||
DATABASE_POOL_SIZE,
|
DATABASE_POOL_SIZE,
|
||||||
DATABASE_POOL_TIMEOUT,
|
DATABASE_POOL_TIMEOUT,
|
||||||
DATABASE_ENABLE_SQLITE_WAL,
|
DATABASE_ENABLE_SQLITE_WAL,
|
||||||
|
DATABASE_ENABLE_SESSION_SHARING,
|
||||||
ENABLE_DB_MIGRATIONS,
|
ENABLE_DB_MIGRATIONS,
|
||||||
)
|
)
|
||||||
from peewee_migrate import Router
|
from peewee_migrate import Router
|
||||||
@@ -164,7 +165,7 @@ get_db = contextmanager(get_session)
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def get_db_context(db: Optional[Session] = None):
|
def get_db_context(db: Optional[Session] = None):
|
||||||
if isinstance(db, Session):
|
if isinstance(db, Session) and DATABASE_ENABLE_SESSION_SHARING:
|
||||||
yield db
|
yield db
|
||||||
else:
|
else:
|
||||||
with get_db() as session:
|
with get_db() as session:
|
||||||
|
|||||||
Reference in New Issue
Block a user