perf(gateway): offload inbound media cache writes

This commit is contained in:
fangliquanflq
2026-08-24 23:08:35 +08:00
committed by kshitij
parent a3d33fe22f
commit cb0b66c161
25 changed files with 262 additions and 134 deletions

View File

@@ -118,10 +118,10 @@ from gateway.platforms.base import (
MessageEvent,
MessageType,
SendResult,
cache_audio_from_bytes,
cache_document_from_bytes,
cache_image_from_bytes,
cache_video_from_bytes,
cache_audio_from_bytes_async,
cache_document_from_bytes_async,
cache_image_from_bytes_async,
cache_video_from_bytes_async,
)
from gateway.config import Platform
@@ -1154,16 +1154,16 @@ class LineAdapter(BasePlatformAdapter):
}.get(msg_type, ".bin")
try:
if msg_type == "image":
return cache_image_from_bytes(data, ext=ext), "image/jpeg"
return await cache_image_from_bytes_async(data, ext=ext), "image/jpeg"
if msg_type == "audio":
media_type = mimetypes.guess_type(f"audio{ext}")[0] or "audio/mp4"
return cache_audio_from_bytes(data, ext=ext), media_type
return await cache_audio_from_bytes_async(data, ext=ext), media_type
if msg_type == "video":
media_type = mimetypes.guess_type(f"video{ext}")[0] or "video/mp4"
return cache_video_from_bytes(data, ext=ext), media_type
return await cache_video_from_bytes_async(data, ext=ext), media_type
document_name = filename or f"line_file{ext}"
return (
cache_document_from_bytes(data, document_name),
await cache_document_from_bytes_async(data, document_name),
mimetypes.guess_type(document_name)[0] or "application/octet-stream",
)
except Exception as exc: