⚡ perf(webdav): 偏移写入分片并取消整文件落盘合并
This commit is contained in:
1 parent
6d825e5fbc
commit
32298bfdeb
12 files changed
+690
-53
No files matched your search
+16
-20
@@ -17,6 +17,7 @@ from apps.base.models import (
|
||||
from apps.admin.services import FileService
|
||||
from apps.base.utils import ip_limit, get_chunk_file_path_name
|
||||
from core.config import refresh_settings
|
||||
from apps.base.upload_sessions import upload_lock
|
||||
from core.logger import logger
|
||||
from apps.admin.trash_management import automatic_trash_reason
|
||||
from core.settings import settings, data_root
|
||||
@@ -65,6 +66,19 @@ async def delete_expire_files():
|
||||
await asyncio.sleep(600)
|
||||
|
||||
|
||||
async def clean_expired_chunk_session(upload_id, expire_time):
|
||||
async with upload_lock(upload_id):
|
||||
session = await UploadChunk.filter(upload_id=upload_id, chunk_index=-1, created_at__lt=expire_time).first()
|
||||
if session is None:
|
||||
return
|
||||
save_path = session.save_path
|
||||
if not save_path:
|
||||
_, _, _, _, save_path = await get_chunk_file_path_name(session.file_name, session.upload_id)
|
||||
await storages[settings.file_storage]().clean_chunks(upload_id, save_path)
|
||||
await UploadChunk.filter(upload_id=upload_id).delete()
|
||||
await StorageReservation.filter(token=f"chunk:{upload_id}").delete()
|
||||
|
||||
|
||||
async def clean_incomplete_uploads():
|
||||
while True:
|
||||
try:
|
||||
@@ -79,27 +93,9 @@ async def clean_incomplete_uploads():
|
||||
|
||||
for session in expired_sessions:
|
||||
try:
|
||||
save_path = session.save_path
|
||||
if not save_path:
|
||||
_, _, _, _, save_path = await get_chunk_file_path_name(
|
||||
session.file_name, session.upload_id
|
||||
)
|
||||
await file_storage.clean_chunks(session.upload_id, save_path)
|
||||
await clean_expired_chunk_session(session.upload_id, expire_time)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"清理分片文件失败 upload_id={session.upload_id}: {e}"
|
||||
)
|
||||
|
||||
try:
|
||||
await UploadChunk.filter(upload_id=session.upload_id).delete()
|
||||
await StorageReservation.filter(
|
||||
token=f"chunk:{session.upload_id}"
|
||||
).delete()
|
||||
logger.info(f"已清理过期上传会话 upload_id={session.upload_id}")
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"删除分片记录失败 upload_id={session.upload_id}: {e}"
|
||||
)
|
||||
logger.error(f"清理分片失败,保留会话等待重试 upload_id={session.upload_id}: {e}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"清理未完成上传任务异常: {e}")
|
||||
|
||||
Reference in new issue
Block a user