fix: 가사/노래/영상 재생성 시 올바른 레코드 업데이트되도록 수정

This commit is contained in:
HyeongBaeYang committed 2026-01-30 15:19:26 +09:00
1 parent 7a0d5a6272
commit c92d6e2135
7 files changed
+92 -62

No files matched your search

+8 -21
View File
@@ -37,7 +37,7 @@ router = APIRouter(prefix="/archive", tags=["Archive"])
- **page_size**: 페이지당 데이터 수 (기본값: 10, 최대: 100)
## 반환 정보
- **items**: 영상 목록 (store_name, region, task_id, result_movie_url, created_at)
- **items**: 영상 목록 (video_id, store_name, region, task_id, result_movie_url, created_at)
- **total**: 전체 데이터 수
- **page**: 현재 페이지
- **page_size**: 페이지당 데이터 수
@@ -53,7 +53,7 @@ GET /archive/videos/?page=1&page_size=10
## 참고
- **본인이 소유한 프로젝트의 영상만 반환됩니다.**
- status가 'completed'인 영상만 반환됩니다.
- 동일한 task_id가 있는 경우 가장 최근에 생성된 1개만 반환됩니다.
- 재생성된 영상 포함 모든 영상이 반환됩니다.
- created_at 기준 내림차순 정렬됩니다.
""",
response_model=PaginatedResponse[VideoListItem],
@@ -149,35 +149,21 @@ async def get_videos(
Project.is_deleted == False,
]
# 쿼리 1: 전체 개수 조회 (task_id 기준 고유 개수)
# 쿼리 1: 전체 개수 조회 (모든 영상)
count_query = (
select(func.count(func.distinct(Video.task_id)))
select(func.count(Video.id))
.join(Project, Video.project_id == Project.id)
.where(*base_conditions)
)
total_result = await session.execute(count_query)
total = total_result.scalar() or 0
logger.debug(f"[get_videos] DEBUG - task_id 기준 고유 개수 (total): {total}")
logger.debug(f"[get_videos] DEBUG - 전체 영상 개수 (total): {total}")
# 서브쿼리: task_id별 최신 Video의 id 조회
subquery = (
select(func.max(Video.id).label("max_id"))
.join(Project, Video.project_id == Project.id)
.where(*base_conditions)
.group_by(Video.task_id)
.subquery()
)
# DEBUG: 서브쿼리 결과 확인
subquery_debug_result = await session.execute(select(subquery.c.max_id))
subquery_ids = [row[0] for row in subquery_debug_result.all()]
logger.debug(f"[get_videos] DEBUG - 서브쿼리 결과 (max_id 목록): {subquery_ids}")
# 쿼리 2: Video + Project 데이터를 JOIN으로 한 번에 조회
# 쿼리 2: Video + Project 데이터를 JOIN으로 한 번에 조회 (모든 영상)
query = (
select(Video, Project)
.join(Project, Video.project_id == Project.id)
.where(Video.id.in_(select(subquery.c.max_id)))
.where(*base_conditions)
.order_by(Video.created_at.desc())
.offset(offset)
.limit(pagination.page_size)
@@ -190,6 +176,7 @@ async def get_videos(
items = []
for video, project in rows:
item = VideoListItem(
video_id=video.id,
store_name=project.store_name,
region=project.region,
task_id=video.task_id,