mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-28 06:22:33 +00:00
perf: posting in a channel takes seconds when many members are online (#32889)
Every message posted in a channel waited until the server had re-checked the login of every online member of that channel, one connected session at a time with a few database lookups each, before the post went through. In a large channel that added seconds to every single message. The result only decides who gets a notification, and the message is already delivered to everyone before this step, so the check now runs right after the post returns, as the first step of the work that sends notifications and bot replies. Members are re-checked exactly as before, including disconnecting any session whose login is no longer valid. Postgres 16, standard channel, median time for a post to return: | Online members | Before | After | | --- | --- | --- | | 100 | 0.37 s | 0.03 s | | 300 | 1.6 s | 0.05 s | | 1,000 | 3.4 s | 0.10 s |
This commit is contained in:
parent
494619062a
commit
a9adb2b78e
1 changed files with 1 additions and 2 deletions
|
|
@ -1481,12 +1481,11 @@ async def post_new_message(
|
|||
except Exception as e:
|
||||
log.debug(e)
|
||||
|
||||
active_user_ids = await get_user_ids_from_room(f'channel:{channel.id}')
|
||||
|
||||
# NOTE: We intentionally do NOT pass db to background_handler.
|
||||
# Background tasks should manage their own short-lived sessions to avoid
|
||||
# holding database connections during slow operations (e.g., LLM calls).
|
||||
async def background_handler():
|
||||
active_user_ids = await get_user_ids_from_room(f'channel:{channel.id}')
|
||||
await create_task(None, app_channel_reply_handler(channel.id, message.id, user.id))
|
||||
await model_response_handler(request, channel, message, user)
|
||||
await send_notification(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue