From 326599b8db0f147918ddd8fb96cc7d98fc521c46 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 19 Feb 2026 23:38:01 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20O(n=C2=B2)=20performance=20in=20get=5Fmes?= =?UTF-8?q?sage=5Flist=20by=20replacing=20insert(0)=20with=20append+revers?= =?UTF-8?q?e=20(#21588)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jordan --- backend/open_webui/utils/misc.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/utils/misc.py b/backend/open_webui/utils/misc.py index a63d425ff..a52dca7a8 100644 --- a/backend/open_webui/utils/misc.py +++ b/backend/open_webui/utils/misc.py @@ -93,12 +93,11 @@ def get_message_list(messages_map, message_id): message_list = [] while current_message: - message_list.insert( - 0, current_message - ) # Insert the message at the beginning of the list + message_list.append(current_message) parent_id = current_message.get("parentId") # Use .get() for safety current_message = messages_map.get(parent_id) if parent_id else None + message_list.reverse() return message_list