feat: 添加 update_video_stats 方法以更新视频统计信息

This commit is contained in:
晓丰 2025-05-22 23:56:38 +08:00
parent f17ff34563
commit 95fed6b6c8

28
DB.py
View File

@ -586,3 +586,31 @@ class DBSA:
cls.push_record_many(payloads) cls.push_record_many(payloads)
except Exception as re: except Exception as re:
print("[Redis 回退失败]", re) print("[Redis 回退失败]", re)
@classmethod
def update_video_stats(cls, locator:dict, stats:dict) -> int:
"""
立即更新 sh_dm_video_v2 表中的统计字段
:param locator: 用于定位行的字典必须包含: v_xid, rn
:param stats: 需要更新的统计字段 {"fans": 633, "videos": 10090, "view": 1678408}
:return: 受影响的行数
"""
v_xid = locator.get("v_xid")
rn = locator.get("rn")
if not v_xid or not rn:
raise ValueError("locator 必须包含 'v_xid''rn'")
params = dict(stats)
params["updatetime"] = int(time.time())
# 使用 Core Table 的 update() 方法
stmt = (
video
.update()
.where(video.c.v_xid == v_xid, video.c.rn == rn)
.values(**params)
)
with _engine.begin() as conn:
result = conn.execute(stmt)
return result.rowcount