mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: enhance memory management and session handling in database operations
- Introduced a shielded async session context manager to ensure safe session closure during cancellations. - Updated various database operations to utilize the new shielded session, preventing orphaned connections. - Added environment variables to optimize glibc memory management, improving overall application performance. - Implemented a function to trim the native heap, allowing for better memory reclamation on Linux systems.
This commit is contained in:
parent
dd3da2bc36
commit
ecb0a25cc8
7 changed files with 76 additions and 17 deletions
|
|
@ -31,8 +31,8 @@ from app.db import (
|
|||
Permission,
|
||||
SearchSpace,
|
||||
User,
|
||||
async_session_maker,
|
||||
get_async_session,
|
||||
shielded_async_session,
|
||||
)
|
||||
from app.schemas.new_chat import (
|
||||
NewChatMessageAppend,
|
||||
|
|
@ -1356,7 +1356,7 @@ async def regenerate_response(
|
|||
# Uses a fresh session since stream_new_chat manages its own.
|
||||
if streaming_completed and message_ids_to_delete:
|
||||
try:
|
||||
async with async_session_maker() as cleanup_session:
|
||||
async with shielded_async_session() as cleanup_session:
|
||||
for msg_id in message_ids_to_delete:
|
||||
_res = await cleanup_session.execute(
|
||||
select(NewChatMessage).filter(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue