Skip to content
Draft

fix:t2i #8013

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions astrbot/core/utils/t2i/network_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ async def render_custom_template(
if options:
default_options |= options

if SHIKI_RUNTIME_TEMPLATE_PATTERN.search(tmpl_str):
tmpl_data = {"shiki_runtime": get_shiki_runtime()} | tmpl_data
tmpl_str = inject_shiki_runtime(tmpl_str)
# 在线程池中执行 Shiki 注入,避免 1.2MB JS 处理阻塞事件循环
loop = asyncio.get_running_loop()
tmpl_str, tmpl_data = await loop.run_in_executor(
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
None, self._prepare_template_sync, tmpl_str, tmpl_data
)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
post_data = {
"tmpl": tmpl_str,
"json": return_url,
Expand Down Expand Up @@ -219,3 +221,11 @@ async def render(
},
return_url,
)

@staticmethod
def _prepare_template_sync(tmpl_str: str, tmpl_data: dict) -> tuple[str, dict]:
"""在线程池中执行的同步模板预处理(避免阻塞事件循环)"""
if SHIKI_RUNTIME_TEMPLATE_PATTERN.search(tmpl_str):
tmpl_data = {"shiki_runtime": get_shiki_runtime()} | tmpl_data
tmpl_str = inject_shiki_runtime(tmpl_str)
return tmpl_str, tmpl_data
Loading