Shorts dedup: per-channel room_id within same Beijing day
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9d87aa48be
commit
765501e225
@ -3442,21 +3442,37 @@ def claim_shorts_job_manual_upload(job_id: str) -> dict[str, Any] | None:
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def has_shorts_job_for_room_day(room_id: str, push_date: str) -> bool:
|
def has_shorts_job_for_room_day(room_id: str, push_date: str, channel_id: str = "") -> bool:
|
||||||
|
"""Return True if this channel already has a non-failed job for room_id on push_date.
|
||||||
|
|
||||||
|
Dedup scope: channel_id + room_id + push_date (Beijing day 00:00-24:00).
|
||||||
|
If channel_id is empty, falls back to global room_id + push_date dedup.
|
||||||
|
"""
|
||||||
if not room_id:
|
if not room_id:
|
||||||
return False
|
return False
|
||||||
with _lock:
|
with _lock:
|
||||||
conn = _connect()
|
conn = _connect()
|
||||||
try:
|
try:
|
||||||
row = conn.execute(
|
if channel_id:
|
||||||
"""
|
row = conn.execute(
|
||||||
SELECT 1 FROM shorts_jobs
|
"""
|
||||||
WHERE room_id = ? AND push_date = ?
|
SELECT 1 FROM shorts_jobs
|
||||||
AND status NOT IN ('failed', 'skipped')
|
WHERE room_id = ? AND push_date = ? AND channel_id = ?
|
||||||
LIMIT 1
|
AND status NOT IN ('failed', 'skipped')
|
||||||
""",
|
LIMIT 1
|
||||||
(room_id, push_date),
|
""",
|
||||||
).fetchone()
|
(room_id, push_date, channel_id),
|
||||||
|
).fetchone()
|
||||||
|
else:
|
||||||
|
row = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT 1 FROM shorts_jobs
|
||||||
|
WHERE room_id = ? AND push_date = ?
|
||||||
|
AND status NOT IN ('failed', 'skipped')
|
||||||
|
LIMIT 1
|
||||||
|
""",
|
||||||
|
(room_id, push_date),
|
||||||
|
).fetchone()
|
||||||
return bool(row)
|
return bool(row)
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
@ -63,8 +63,6 @@ def _enqueue_job(
|
|||||||
if room_id.startswith("yt:"):
|
if room_id.startswith("yt:"):
|
||||||
return None
|
return None
|
||||||
day = push_date_from_ts(float((session or {}).get("started_at") or time.time()))
|
day = push_date_from_ts(float((session or {}).get("started_at") or time.time()))
|
||||||
if settings.get("shorts_dedupe_room_day", True) and room_id and db.has_shorts_job_for_room_day(room_id, day):
|
|
||||||
return None
|
|
||||||
channel: dict[str, Any] | None = None
|
channel: dict[str, Any] | None = None
|
||||||
if channel_pk:
|
if channel_pk:
|
||||||
ch = db.get_shorts_channel(channel_pk)
|
ch = db.get_shorts_channel(channel_pk)
|
||||||
@ -77,6 +75,10 @@ def _enqueue_job(
|
|||||||
channel = db.pick_shorts_channel(day, settings)
|
channel = db.pick_shorts_channel(day, settings)
|
||||||
if not channel:
|
if not channel:
|
||||||
return None
|
return None
|
||||||
|
# Dedup: same channel + same room_id within the same Beijing day is not allowed
|
||||||
|
if settings.get("shorts_dedupe_room_day", True) and room_id:
|
||||||
|
if db.has_shorts_job_for_room_day(room_id, day, channel_id=str(channel["id"])):
|
||||||
|
return None
|
||||||
sid = str((session or {}).get("id") or room.get("active_session_id") or "")
|
sid = str((session or {}).get("id") or room.get("active_session_id") or "")
|
||||||
job = db.create_shorts_job(
|
job = db.create_shorts_job(
|
||||||
session_id=sid,
|
session_id=sid,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user