mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-06 02:48:04 +00:00
perf(retrieval): make URL fetch and file hash non-blocking with asyncio.to_thread
- Wrap get_content_from_url() in asyncio.to_thread() inside get_sources_from_items() to prevent sync requests.get() from blocking the event loop when users attach URL sources to chat messages. The same function was already properly wrapped at retrieval.py:1839. - Wrap hashlib.sha256(contents).hexdigest() in asyncio.to_thread() inside upload_file_handler() to prevent CPU-bound hashing from blocking the event loop during file uploads (44ms/100MB, scales linearly with file size).
This commit is contained in:
parent
0ffc04797f
commit
92a346575b
1 changed files with 3 additions and 1 deletions
|
|
@ -317,7 +317,9 @@ async def upload_file_handler(
|
|||
|
||||
# SHA-256 of raw uploaded bytes for incremental sync diffing.
|
||||
# If the client pre-computed and sent file_hash, use that.
|
||||
file_hash = file_metadata.get('file_hash') or hashlib.sha256(contents).hexdigest()
|
||||
file_hash = file_metadata.get('file_hash') or await asyncio.to_thread(
|
||||
lambda: hashlib.sha256(contents).hexdigest()
|
||||
)
|
||||
|
||||
file_item = await Files.insert_new_file(
|
||||
user.id,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue