fix(async): offload file metadata checks

This commit is contained in:
InfinityPacer
2026-08-23 12:06:52 +08:00
parent 56293bc82a
commit e8cfe272c4
9 changed files with 182 additions and 12 deletions
+6 -1
View File
@@ -9,6 +9,8 @@ from pathlib import Path
from typing import Any, Optional, Tuple, Union
from uuid import UUID
from fastapi.concurrency import run_in_threadpool
from app.runtime.settings import RuntimeSettingsCompat
settings = RuntimeSettingsCompat()
@@ -137,7 +139,10 @@ class AcoustIdModule(_ModuleBase):
) -> Optional[str]:
"""异步读取音频指纹并返回高置信匹配的 MusicBrainz Recording ID。"""
file_path = Path(path)
if not self._fpcalc_path or not file_path.is_file():
if not self._fpcalc_path or not await run_in_threadpool(
Path.is_file,
file_path,
):
return None
cache_key = self._file_cache_key(file_path)
if cache_key:
+10 -1
View File
@@ -8,6 +8,7 @@ from urllib.parse import quote
import discord
from discord import app_commands
import httpx
from fastapi.concurrency import run_in_threadpool
from app.runtime.settings import RuntimeSettingsCompat
@@ -28,6 +29,11 @@ PARSE_FIELD_TYPES = {
}
def _is_regular_file(path: Path) -> bool:
"""判断路径是否仍指向可发送的普通文件。"""
return path.exists() and path.is_file()
class Discord:
"""
Discord Bot 通知与交互实现(基于 discord.py 2.6.4
@@ -780,7 +786,10 @@ class Discord:
return False, None
local_file = Path(file_path)
if not local_file.exists() or not local_file.is_file():
if not await run_in_threadpool(
_is_regular_file,
local_file,
):
logger.error(f"Discord发送文件失败,文件不存在: {local_file}")
return False, None