Skip to content

Commit 8646aeb

Browse files
committed
refac/fix: DATABASE_ENABLE_SESSION_SHARING env var
1 parent 5990c51 commit 8646aeb

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

backend/open_webui/env.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ def parse_section(section):
341341
except Exception:
342342
DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = 0.0
343343

344+
# When enabled, get_db_context reuses existing sessions; set to False to always create new sessions
345+
DATABASE_ENABLE_SESSION_SHARING = (
346+
os.environ.get("DATABASE_ENABLE_SESSION_SHARING", "False").lower() == "true"
347+
)
348+
344349
# Enable public visibility of active user count (when disabled, only admins can see it)
345350
ENABLE_PUBLIC_ACTIVE_USERS_COUNT = (
346351
os.environ.get("ENABLE_PUBLIC_ACTIVE_USERS_COUNT", "True").lower() == "true"

backend/open_webui/internal/db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DATABASE_POOL_SIZE,
1515
DATABASE_POOL_TIMEOUT,
1616
DATABASE_ENABLE_SQLITE_WAL,
17+
DATABASE_ENABLE_SESSION_SHARING,
1718
ENABLE_DB_MIGRATIONS,
1819
)
1920
from peewee_migrate import Router
@@ -164,7 +165,7 @@ def get_session():
164165

165166
@contextmanager
166167
def get_db_context(db: Optional[Session] = None):
167-
if isinstance(db, Session):
168+
if isinstance(db, Session) and DATABASE_ENABLE_SESSION_SHARING:
168169
yield db
169170
else:
170171
with get_db() as session:

0 commit comments

Comments
 (0)