비동기 적용
This commit is contained in:
1 parent
95d90dcb50
commit
153b9f0ca4
6 files changed
+534
-161
No files matched your search
@@ -107,9 +107,12 @@ async def generate_video(
|
||||
"""
|
||||
print(f"[generate_video] START - task_id: {task_id}, orientation: {orientation}")
|
||||
try:
|
||||
# 1. task_id로 Project 조회
|
||||
# 1. task_id로 Project 조회 (중복 시 최신 것 선택)
|
||||
project_result = await session.execute(
|
||||
select(Project).where(Project.task_id == task_id)
|
||||
select(Project)
|
||||
.where(Project.task_id == task_id)
|
||||
.order_by(Project.created_at.desc())
|
||||
.limit(1)
|
||||
)
|
||||
project = project_result.scalar_one_or_none()
|
||||
|
||||
@@ -121,9 +124,12 @@ async def generate_video(
|
||||
)
|
||||
print(f"[generate_video] Project found - project_id: {project.id}, task_id: {task_id}")
|
||||
|
||||
# 2. task_id로 Lyric 조회
|
||||
# 2. task_id로 Lyric 조회 (중복 시 최신 것 선택)
|
||||
lyric_result = await session.execute(
|
||||
select(Lyric).where(Lyric.task_id == task_id)
|
||||
select(Lyric)
|
||||
.where(Lyric.task_id == task_id)
|
||||
.order_by(Lyric.created_at.desc())
|
||||
.limit(1)
|
||||
)
|
||||
lyric = lyric_result.scalar_one_or_none()
|
||||
|
||||
@@ -593,14 +599,19 @@ async def get_videos(
|
||||
result = await session.execute(query)
|
||||
videos = result.scalars().all()
|
||||
|
||||
# Project 정보와 함께 VideoListItem으로 변환
|
||||
# Project 정보 일괄 조회 (N+1 문제 해결)
|
||||
project_ids = [v.project_id for v in videos if v.project_id]
|
||||
projects_map: dict = {}
|
||||
if project_ids:
|
||||
projects_result = await session.execute(
|
||||
select(Project).where(Project.id.in_(project_ids))
|
||||
)
|
||||
projects_map = {p.id: p for p in projects_result.scalars().all()}
|
||||
|
||||
# VideoListItem으로 변환
|
||||
items = []
|
||||
for video in videos:
|
||||
# Project 조회 (video.project_id 직접 사용)
|
||||
project_result = await session.execute(
|
||||
select(Project).where(Project.id == video.project_id)
|
||||
)
|
||||
project = project_result.scalar_one_or_none()
|
||||
project = projects_map.get(video.project_id)
|
||||
|
||||
item = VideoListItem(
|
||||
store_name=project.store_name if project else None,
|
||||
@@ -611,13 +622,6 @@ async def get_videos(
|
||||
)
|
||||
items.append(item)
|
||||
|
||||
# 개별 아이템 로그
|
||||
print(
|
||||
f"[get_videos] Item - store_name: {item.store_name}, region: {item.region}, "
|
||||
f"task_id: {item.task_id}, result_movie_url: {item.result_movie_url}, "
|
||||
f"created_at: {item.created_at}"
|
||||
)
|
||||
|
||||
response = PaginatedResponse.create(
|
||||
items=items,
|
||||
total=total,
|
||||
|
||||
Reference in new issue
Block a user