mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-07 08:27:05 +00:00
refac: run the built-in file grep off the event loop (#29621)
The built-in chat and knowledge grep tools awaited their matching helper directly, so the search ran on the event loop and held it for as long as the match took. Both call sites now hand the helper to a worker thread. Output and error handling are unchanged: 17 cases (literal, regex, case-insensitive, count-only, no-match, invalid pattern, rejected quantifiers, missing file data, result truncation) compare byte-for-byte against the previous behaviour. The matcher's time budget lives in a contextvar, which asyncio.to_thread copies into the worker, so budget scoping still behaves as before.
This commit is contained in:
parent
cc4d84b93d
commit
82f11b14c9
1 changed files with 2 additions and 2 deletions
|
|
@ -2489,7 +2489,7 @@ async def grep_chat_files(
|
|||
if not files_to_search:
|
||||
return JSONCodec.dumps({'error': 'No accessible files found'})
|
||||
|
||||
return _grep_file_models(files_to_search, pattern, case_insensitive, count_only)
|
||||
return await asyncio.to_thread(_grep_file_models, files_to_search, pattern, case_insensitive, count_only)
|
||||
except Exception as e:
|
||||
log.exception(f'grep_chat_files error: {e}')
|
||||
return JSONCodec.dumps({'error': str(e)})
|
||||
|
|
@ -2727,7 +2727,7 @@ async def grep_knowledge_files(
|
|||
if not files_to_search:
|
||||
return JSONCodec.dumps({'error': 'No accessible files found'})
|
||||
|
||||
return _grep_file_models(files_to_search, pattern, case_insensitive, count_only)
|
||||
return await asyncio.to_thread(_grep_file_models, files_to_search, pattern, case_insensitive, count_only)
|
||||
|
||||
except Exception as e:
|
||||
log.exception(f'grep_knowledge_files error: {e}')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue