fix(media): tried集合分片进NOT IN(3万+msg_id超SQLite变量上限,42k后崩;每晚全量媒体步同bug)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -478,7 +478,13 @@ async def download_message_images(
|
||||
.limit(batch_size)
|
||||
)
|
||||
if tried:
|
||||
stmt = stmt.where(Message.msg_id.not_in(tried))
|
||||
# 分片进 NOT IN —— 单次塞全部 tried(3万+)会超 SQLite 变量上限
|
||||
# (默认 32766/999),2026-08-20 实测 42k 后崩;每次最多 500 个。
|
||||
tried_list = list(tried)
|
||||
conds = []
|
||||
for i in range(0, len(tried_list), 500):
|
||||
conds.append(Message.msg_id.not_in(tried_list[i:i + 500]))
|
||||
stmt = stmt.where(sa.and_(*conds))
|
||||
rows = (await session.execute(stmt)).all()
|
||||
if not rows:
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user