mirror of
https://github.com/open-webui/open-webui.git
synced 2026-02-24 12:11:56 +01:00
fix: More n+1 channel perf fixes (#20460)
This commit is contained in:
@@ -1414,14 +1414,16 @@ async def get_channel_thread_messages(
|
||||
)
|
||||
|
||||
message_list = Messages.get_messages_by_parent_id(id, message_id, skip, limit, db=db)
|
||||
users = {}
|
||||
|
||||
if not message_list:
|
||||
return []
|
||||
|
||||
# Batch fetch all users in a single query (fixes N+1 problem)
|
||||
user_ids = list(set(m.user_id for m in message_list))
|
||||
users = {u.id: u for u in Users.get_users_by_user_ids(user_ids, db=db)}
|
||||
|
||||
messages = []
|
||||
for message in message_list:
|
||||
if message.user_id not in users:
|
||||
user = Users.get_user_by_id(message.user_id, db=db)
|
||||
users[message.user_id] = user
|
||||
|
||||
messages.append(
|
||||
MessageUserResponse(
|
||||
**{
|
||||
|
||||
Reference in New Issue
Block a user