fix(from-assets): 修复冲突检测排除自身时间段
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2m53s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m57s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 3m13s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m4s
AI Code Review / AI Code Review (pull_request) Failing after 4m6s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m25s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m38s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m12s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m52s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2m53s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m57s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 3m13s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m4s
AI Code Review / AI Code Review (pull_request) Failing after 4m6s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m25s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m38s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m12s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m52s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
冲突检测时used_segments包含当前片段自己的随机时间,导致推荐时间 永远与自身冲突而无法更新。改为用clip_id映射,检测时排除自身, 只检查其他片段的原始时间+已更新的推荐时间。
This commit is contained in:
@@ -729,15 +729,21 @@ def _update_mediakit_recommendations_async( # pragma: no cover
|
||||
logger.info("后台任务: plan_id=%s 无片段,跳过更新", plan_id)
|
||||
return
|
||||
|
||||
# 按 asset_id 分组,初始化已使用时间段(包含所有片段的当前随机时间)
|
||||
used_segments: dict[str, list[tuple[float, float]]] = {}
|
||||
# 按 asset_id 分组,记录所有片段的当前时间段
|
||||
# 使用 clip_id 作为 key,便于冲突检测时排除自身
|
||||
clip_current_times: dict[str, tuple[str, float, float]] = {}
|
||||
for clip in clips:
|
||||
aid = getattr(clip, "asset_id", "") or ""
|
||||
if aid and clip.start_time is not None:
|
||||
used_segments.setdefault(aid, []).append(
|
||||
(clip.start_time, clip.start_time + clip.duration)
|
||||
clip_current_times[clip.id] = (
|
||||
aid,
|
||||
clip.start_time,
|
||||
clip.start_time + clip.duration,
|
||||
)
|
||||
|
||||
# 已更新的时间段(已成功应用推荐时间的片段)
|
||||
updated_segments: dict[str, list[tuple[float, float]]] = {}
|
||||
|
||||
# 遍历片段,按 asset_id 匹配推荐时间
|
||||
for clip in clips:
|
||||
asset_id = getattr(clip, "asset_id", "") or ""
|
||||
@@ -766,10 +772,16 @@ def _update_mediakit_recommendations_async( # pragma: no cover
|
||||
)
|
||||
continue
|
||||
|
||||
# 构建排除当前片段后的占用列表(其他片段的原始时间 + 已更新的推荐时间)
|
||||
other_segments: list[tuple[float, float]] = []
|
||||
for cid, (caid, cs, ce) in clip_current_times.items():
|
||||
if caid == asset_id and cid != clip.id:
|
||||
other_segments.append((cs, ce))
|
||||
# 加上已成功更新的推荐时间段
|
||||
other_segments.extend(updated_segments.get(asset_id, []))
|
||||
|
||||
# 检查是否与同素材其他片段时间段冲突
|
||||
if _recommended_time_conflicts(
|
||||
recommended_start, clip_duration, used_segments.get(asset_id, [])
|
||||
):
|
||||
if _recommended_time_conflicts(recommended_start, clip_duration, other_segments):
|
||||
logger.info(
|
||||
"后台任务: 推荐时间冲突,跳过: asset_id=%s recommended=%.2f",
|
||||
asset_id,
|
||||
@@ -779,7 +791,7 @@ def _update_mediakit_recommendations_async( # pragma: no cover
|
||||
|
||||
# 更新片段的 start_time
|
||||
plan_svc.update_clip(clip.id, start_time=recommended_start)
|
||||
used_segments.setdefault(asset_id, []).append(
|
||||
updated_segments.setdefault(asset_id, []).append(
|
||||
(recommended_start, recommended_start + clip_duration)
|
||||
)
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user