From a9617ca2187920734e2be5f90c5f119c09850ff5 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 14 Jul 2026 01:15:29 -0400 Subject: [PATCH] refac --- backend/open_webui/models/chats.py | 2 +- backend/open_webui/socket/main.py | 3 +++ backend/open_webui/utils/context_compaction.py | 5 ++++- backend/open_webui/utils/middleware.py | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index d8211a7c47..a4286d1520 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -834,7 +834,7 @@ class ChatTable: history['messages'][message_id]['statusHistory'] = status_history chat['history'] = history - return await self.update_chat_by_id(id, chat) + return await self.update_chat_by_id(id, chat, touch=False) async def add_message_files_by_id_and_message_id(self, id: str, message_id: str, files: list[dict]) -> list[dict]: async with get_async_db_context() as session: diff --git a/backend/open_webui/socket/main.py b/backend/open_webui/socket/main.py index 3393b73bb2..1295629d3c 100644 --- a/backend/open_webui/socket/main.py +++ b/backend/open_webui/socket/main.py @@ -997,6 +997,7 @@ async def get_event_emitter(request_info, update_db=True): { 'embeds': embeds, }, + touch=False, ) elif event_type == 'files': @@ -1014,6 +1015,7 @@ async def get_event_emitter(request_info, update_db=True): { 'files': files, }, + touch=False, ) elif event_type in ('source', 'citation'): @@ -1033,6 +1035,7 @@ async def get_event_emitter(request_info, update_db=True): { 'sources': sources, }, + touch=False, ) if 'user_id' in request_info and 'chat_id' in request_info and 'message_id' in request_info: diff --git a/backend/open_webui/utils/context_compaction.py b/backend/open_webui/utils/context_compaction.py index 3b6c74017a..6e0eee379b 100644 --- a/backend/open_webui/utils/context_compaction.py +++ b/backend/open_webui/utils/context_compaction.py @@ -115,6 +115,7 @@ async def compact_messages_for_request( chat_id, checkpoint_message_id, {'contextSummary': summary}, + touch=False, ) log.info( @@ -172,7 +173,9 @@ async def compact_chat_branch(request, user, chat: Any, model_id: str, models: d previous_summary, config['prompt_template'], ) - await Chats.upsert_message_to_chat_by_id_and_message_id(chat.id, current_id, {'contextSummary': summary}) + await Chats.upsert_message_to_chat_by_id_and_message_id( + chat.id, current_id, {'contextSummary': summary}, touch=False + ) return { 'ok': True, diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 17cda8966e..67a49993a3 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -3465,6 +3465,7 @@ async def non_streaming_chat_response_handler(response, ctx): { 'selectedModelId': response_data['selected_model_id'], }, + touch=False, ) choices = response_data.get('choices', []) @@ -4061,6 +4062,7 @@ async def streaming_chat_response_handler(response, ctx): { 'selectedModelId': model_id, }, + touch=False, ) await event_emitter( { @@ -5261,12 +5263,14 @@ async def streaming_chat_response_handler(response, ctx): metadata['chat_id'], metadata['message_id'], {'done': True, 'usage': usage}, + touch=False, ) else: await Chats.upsert_message_to_chat_by_id_and_message_id( metadata['chat_id'], metadata['message_id'], {'done': True}, + touch=False, ) # Send a webhook notification if the user is not active @@ -5333,6 +5337,7 @@ async def streaming_chat_response_handler(response, ctx): metadata['chat_id'], metadata['message_id'], {'done': True}, + touch=False, ) try: