feat: P2V 파이프라인 연동 및 좋아요·댓글·공유 지원
- 무빙 포스터(p2v_video)·롱컷(p2v_playreel) 파이프라인과 워커, 갤러리·내 콘텐츠 노출 - 좋아요·댓글: comment/video_reaction에 p2v_playreel_id 추가, 종류별 CHECK 확장 - P2V 소프트 삭제(is_deleted), queued/running 삭제 차단 - 공개 상세·공유 OG 페이지 추가 - 삭제된 부모 댓글이 목록에서 사라지던 has_live_reply 서브쿼리 버그 수정 - 마이그레이션: migration_2026-10-15_p2v_reactions.sql
This commit is contained in:
1 parent
bb1ea12958
commit
b16d4a8f1b
126 files changed
+6921
-62
No files matched your search
@@ -12,6 +12,8 @@ from sqlalchemy import delete, insert, tuple_
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.database.like_cache import (
|
||||
CT_P2V_PLAYREEL,
|
||||
CT_P2V_VIDEO,
|
||||
CT_SSUL,
|
||||
CT_VIDEO,
|
||||
commit_dirty_processing,
|
||||
@@ -19,7 +21,7 @@ from app.database.like_cache import (
|
||||
is_user_liked,
|
||||
)
|
||||
from app.database.session import get_session
|
||||
# 썰박스 좋아요도 같은 Redis write-behind 큐 + **같은 테이블**(video_reaction)을
|
||||
# 썰박스·P2V 좋아요도 같은 Redis write-behind 큐 + **같은 테이블**(video_reaction)을
|
||||
# 쓰므로 여기서 함께 플러시한다. 큐가 하나라 스케줄러를 늘릴 필요가 없다.
|
||||
from app.video.models import VideoReaction
|
||||
from config import internal_settings
|
||||
@@ -59,12 +61,18 @@ async def flush_reactions(
|
||||
|
||||
logger.info(f"[REACTION_FLUSH] START - dirty 항목 {len(entries)}건")
|
||||
|
||||
# 두 종류가 **같은 테이블**(video_reaction)에 들어간다. 대상 컬럼만 다르다.
|
||||
# ADO2 는 video_id, 썰박스는 content_id 를 채운다(나머지는 NULL, CHECK 로 강제).
|
||||
id_col_of = {CT_VIDEO: "video_id", CT_SSUL: "content_id"}
|
||||
# 모든 종류가 **같은 테이블**(video_reaction)에 들어간다. 대상 컬럼만 다르다.
|
||||
# 종류마다 자기 컬럼만 채운다(나머지는 NULL, CHECK 로 정확히 하나를 강제).
|
||||
id_col_of = {
|
||||
CT_VIDEO: "video_id",
|
||||
CT_SSUL: "content_id",
|
||||
CT_P2V_VIDEO: "p2v_video_id",
|
||||
CT_P2V_PLAYREEL: "p2v_playreel_id",
|
||||
}
|
||||
id_cols = tuple(id_col_of.values())
|
||||
adds: list[dict] = []
|
||||
# (컬럼명, 대상 id, user_uuid) — 삭제는 컬럼이 달라 종류별로 묶어야 한다
|
||||
dels: dict[str, list[tuple[int, str]]] = {"video_id": [], "content_id": []}
|
||||
dels: dict[str, list[tuple[int, str]]] = {col: [] for col in id_cols}
|
||||
|
||||
# Redis 현재 상태 기준으로 add / delete 분류
|
||||
for ctype, content_id, user_uuid in entries:
|
||||
@@ -87,10 +95,10 @@ async def flush_reactions(
|
||||
# 부분 반영이 나면 Redis processing SET 이 남아 다음 회차에 재시도되는데,
|
||||
# INSERT IGNORE + UNIQUE 로 멱등이라 중복 반영은 안전하다.
|
||||
#
|
||||
# ⚠️ adds 는 종류별로 키가 달라(video_id vs content_id) 한 번의
|
||||
# ⚠️ adds 는 종류별로 키가 달라(video_id, content_id, p2v_*_id) 한 번의
|
||||
# `values(adds)` 로 묶으면 안 된다 — SQLAlchEmy 가 첫 dict 의 키로
|
||||
# 컬럼 목록을 정하므로 다른 종류의 값이 누락된다. 종류별로 나눠 실행한다.
|
||||
for id_col in ("video_id", "content_id"):
|
||||
for id_col in id_cols:
|
||||
rows = [a for a in adds if id_col in a]
|
||||
if rows:
|
||||
await session.execute(
|
||||
|
||||
@@ -44,6 +44,11 @@ from app.database.like_cache import (
|
||||
from app.credit.exceptions import InsufficientCreditError
|
||||
from app.credit.services.credit_service import deduct_credit_for_job
|
||||
from app.ssulbox.constants import JOB_TYPE_VIDEO as CREDIT_JOB_TYPE_VIDEO
|
||||
from app.p2v.services.public_content import (
|
||||
P2V_TYPES,
|
||||
REACTION_COLUMN,
|
||||
public_exists_query,
|
||||
)
|
||||
from app.ssulbox.models import SsulContent
|
||||
from app.utils.logger import get_logger
|
||||
from app.video.models import Video, VideoReaction
|
||||
@@ -1055,14 +1060,17 @@ async def get_all_videos(
|
||||
)
|
||||
async def toggle_like(
|
||||
video_id: int,
|
||||
type: Literal["video", "ssul"] = Query(
|
||||
type: Literal["video", "ssul", "p2v_video", "p2v_playreel"] = Query(
|
||||
default="video",
|
||||
description="콘텐츠 종류. video.id 와 ssul_content.id 가 겹치므로 반드시 함께 보낼 것",
|
||||
description=(
|
||||
"콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스, p2v_video: 무빙 포스터, "
|
||||
"p2v_playreel: 롱컷). id 가 종류별로 겹치므로 반드시 함께 보낼 것"
|
||||
),
|
||||
),
|
||||
current_user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
) -> LikeToggleResponse:
|
||||
"""영상/썰박스 좋아요를 토글합니다.
|
||||
"""영상/썰박스/P2V 좋아요를 토글합니다.
|
||||
|
||||
Write-Behind 패턴:
|
||||
1. Redis user-set / count를 즉시 원자적으로 업데이트 (Lua script)
|
||||
@@ -1088,6 +1096,9 @@ async def toggle_like(
|
||||
)
|
||||
# DB backfill 시 반응 행을 찾는 컬럼 — 썰박스 행은 content_id 가 채워져 있다
|
||||
target_col = VideoReaction.content_id
|
||||
elif type in P2V_TYPES:
|
||||
exists_q = public_exists_query(type, video_id)
|
||||
target_col = REACTION_COLUMN[type]
|
||||
else:
|
||||
exists_q = select(Video.id).where(
|
||||
Video.id == video_id,
|
||||
|
||||
Reference in new issue
Block a user