From 375388578104b771b285ec73dd5551c3cf8ba63c Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Sun, 1 Jun 2025 18:48:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=E4=BB=A5=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E9=94=AE=E5=AF=B9=E6=AF=94=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/DB.py b/DB.py index 0640def..c4847f7 100644 --- a/DB.py +++ b/DB.py @@ -602,17 +602,18 @@ class DBSA: if not op_rows and not vid_rows: return - existing_vid_ids = set() + existing_keys = set() if vid_rows: - all_v_ids = list({row["v_id"] for row in vid_rows}) + # 收集 (v_xid, rn) 对,应与 video 表中的唯一索引匹配 + all_keys = list({(row["v_xid"], row["rn"]) for row in vid_rows}) conn = _engine.connect() try: sel_vid = ( video.select() - .with_only_columns([video.c.v_id]) - .where(video.c.v_id.in_(all_v_ids)) + .with_only_columns(video.c.v_xid, video.c.rn) + .where(tuple_(video.c.v_xid, video.c.rn).in_(all_keys)) ) - existing_vid_ids = {row.v_id for row in conn.execute(sel_vid).fetchall()} + existing_keys = {(row.v_xid, row.rn) for row in conn.execute(sel_vid).fetchall()} except Exception as e: logger.info(f"[DBSA] 查询 video 表时异常: {e}") try: @@ -624,11 +625,13 @@ class DBSA: conn.close() for i, vid_row in enumerate(vid_rows): - if vid_row["v_id"] in existing_vid_ids: - op_rows[i]["is_repeat"] = 1 # 标记为更新 + key = (vid_row["v_xid"], vid_row["rn"]) + if key in existing_keys: + op_rows[i]["is_repeat"] = 1 else: - op_rows[i]["is_repeat"] = 2 # 标记为插入 + op_rows[i]["is_repeat"] = 2 + # 以下作者表、日志表和视频表写入逻辑保持不变... authors_map = {} now_ts = int(time.time()) for data in payloads: