mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 02:57:57 -05:00
perf: keep the server responsive during large skill imports and exports (#35250)
Importing or previewing a large skill archive, or exporting skills as a zip, froze every other user's requests on the server while the archive was unpacked or compressed. Exporting a 47 MB skill stalled the server for about a second. Unpacking and compressing now run without holding up other users, and the imported skills and exported archives are unchanged. <table> <tr><th>Action (47 MB skill)</th><th>Longest server stall before</th><th>After</th></tr> <tr><td>Import zip</td><td>361 ms</td><td>53 ms</td></tr> <tr><td>Import folder</td><td>334 ms</td><td>111 ms</td></tr> <tr><td>Export zip</td><td>1005 ms</td><td>17 ms</td></tr> </table> Relates to #35245
This commit is contained in:
1 parent
b017958361
commit
0e984be144
1 file changed
+4
-3
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import mimetypes
|
||||
@@ -194,7 +195,7 @@ async def export_skills(
|
||||
if format in ('zip', 'skill'):
|
||||
filename = f'{skills[0].id}.skill' if format == 'skill' else 'skills.zip'
|
||||
return Response(
|
||||
zip_export(packages),
|
||||
await asyncio.to_thread(zip_export, packages),
|
||||
media_type='application/zip',
|
||||
headers={'Content-Disposition': f'attachment; filename="{filename}"'},
|
||||
)
|
||||
@@ -732,7 +733,7 @@ async def read_import(files: list[UploadFile]):
|
||||
|
||||
folder_files.append(encode_file(validate_path(file.filename), data))
|
||||
else:
|
||||
packages.extend(parse_import(data, file.filename or ''))
|
||||
packages.extend(await asyncio.to_thread(parse_import, data, file.filename or ''))
|
||||
if folder_files:
|
||||
roots = sorted(f['path'][: -len('SKILL.md')] for f in folder_files if f['path'].endswith('/SKILL.md'))
|
||||
roots = [root for root in roots if not any(root != parent and root.startswith(parent) for parent in roots)]
|
||||
@@ -744,7 +745,7 @@ async def read_import(files: list[UploadFile]):
|
||||
package = {
|
||||
'files': [{**f, 'path': f['path'][len(root) :]} for f in folder_files if f['path'].startswith(root)]
|
||||
}
|
||||
packages.extend(parse_import(json.dumps(package).encode(), 'skill.json'))
|
||||
packages.extend(await asyncio.to_thread(parse_import, json.dumps(package).encode(), 'skill.json'))
|
||||
if sum(len(file_bytes(f)) for p in packages for f in p['files']) > MAX_IMPORT_BYTES:
|
||||
raise ValueError('Import exceeds 200 MiB decoded')
|
||||
return packages
|
||||
|
||||
Reference in new issue
Block a user